Jump to content

  • Log In with Google      Sign In   
  • Create Account

WiredCat

Member Since 09 Apr 2011
Offline Last Active Today, 03:00 AM

Topics I've Started

C++ how to declare something that isn't declared?!?

18 December 2014 - 08:22 AM

struct TSubparticle
{
TSubparticleP * <-- here i want to declare that typedef below
};

typedef TSubparticle * TSubparticleP;

cheers.


constructor for class that contains another class and constructor C++

17 December 2014 - 02:49 AM

i have this:





template <class _cType> class t3dpoint {
        public:
_cType x;
_cType y;
_cType z;

t3dpoint<_cType>() : x(_cType(0.0)), y(_cType(0.0)), z(_cType(0.0))   //t3dpoint() : x(_cType(0.0) etc
{ }

 };

 

template <class _cType> class  t4dpoint : public t3dpoint<_cType> {

public:
_cType w;

 t4dpoint<_cType>() : x(0.0), y(0.0), z(0.0), w(1.0) <-- [BCC32 Error] DxcMath.h(282): E2312 't3dpoint<float>::x' is not an unambiguous base class of 't4dpoint<float>'
{ }

};

now i could change this to 





t4dpoint<_cType>() { x = 0.0; y = 0.0; z = 0.0; w = 1.0;  return *this; }

but i rather stick to this implementation:





t4dpoint<_cType>() : x(0.0), y(0.0), z(0.0), w(1.0) 

any idea how to deal with this?

 

sorry about that code its this post editor fault


Force and movement

12 December 2014 - 03:18 AM

I dont understand one thing since:

dt = time; -> 0.0330;
Acceleration = result_force / mass;
pos = pos + (vel * dt);
vel = vel + (Acceleration * dt);

and since i want to move player with such function i need to force max speed

 

same with tank movement, whenever i apply forward force to a tank and even if it has friction added which makes forward movement vector smaller

it will be added so after lets say 2 hours tank and player could reach speed of light. 

THe thing i dont understand is how can i force them not to go beyound max vel


static friction

11 December 2014 - 11:57 PM

since i cant find any info about this:

will 

 

something that has area of 1 m^2 and mass of 1000 kg

 

have the same friction as the same material on same surface but

 

2 m^2 and 500 kg mass

 

?


Shadowmapping

07 December 2014 - 05:09 PM

Hi there i try to implement shadowmapping, hwever i get something like this:

shadfail.jpg

 

 

 

So far i managed to see if i get proper depth map (and yes i have good depth texture)

 

So i think problem is with mapping vertex/fragment coords into shadowmap texture space and reading its z value (not from shadowmap)

 

 

 

Maybe first ill explain how i am doing everything: (or at least i try to do)

 

I set viewport to 1024x512, set the same shadowmap texture size, set perspective projection matrix to znear 10 z far 1000 000.

 

then i do actual drawing:

 

 

Clear depth and color buff

Render the scene from light POV, copy depth data to the texture

 

Clear depth and color buff

Render the scene from camera POV and send shadowMVPmatrix * texturebias matrix to the shader:

Matrix44<double> SMVP = ( (ACTUAL_MODEL * shadowView) * ACTUAL_PROJECTION ) * ShadowbiasTex;

 

where ShadowbiasTex is





void LoadBiasIdentity()
{
(*this) = Matrix44<T>( 
0.5, 0.0, 0.0, 0.0,
0.0, 0.5, 0.0, 0.0,
0.0, 0.0, 0.5, 0.0,
0.5, 0.5, 0.5, 1.0);
Transpose();
}

Now for the shadowmapping vertex and frag shaders:

 

in Vertex Shader:

 

  1. Compute VertexScreenPos = MVPmatrix * vertex;
  2. Compute VertexShadowScrPos = SMVPTmatrix * vertex;
  3. Send VertexShadowScrPos to fragment shader
  4. output vertex color = 1,1,1,1
  5. texcoords are passed not touched

 

in Fragment Shader

 

  1. VertexShadowScrPos.z = VertexShadowScrPos.z / VertexShadowScrPos.w;
  2. float DepthInLightPOV = GetTextureSampleFrom(VertexShadowScrPos.x, VertexShadowScrPos.y);
  3. add little tiny small offset to it     DepthInLightPOV = DepthInLightPOV + 0.0000625;
  4. float RESULT_COLOR = DepthInLightPOV - VertexShadowScrPos.z; 
  5. clamp result 0..1 and multiple it by 100000 and clamp again to 0..1 <-- depth compare if RESULT_COLOR is less than 0 then we are in shadow if not we are not in the shadow
  6. Set fragment color as RESULT_COLOR

 

 

Someone can ask for the code code is bad and will liekly rip off your eyes but here it is:

 

OpenGL rendering pass:





void Draw() {
//we start with activetexture 0
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT);
if ( glIsEnabled(GL_DEPTH_TEST) == false) glEnable(GL_DEPTH_TEST);

gluPerspectiveA(90.0, 2.0, 10.0,  1000.0 * 1000.0);  

ACTUAL_MODEL.LoadIdentity();
FPP_CAM->SetView(); //sets ACTUAL_VIEW

//shadowmapping
if (village != NULL)												{
glActiveTextureARB(GL_TEXTURE1_ARB); //texturing already enabled (was enabled during initialization)
if ( glIsEnabled(GL_DEPTH_TEST) == false) glEnable(GL_DEPTH_TEST);


glEnable( GL_VERTEX_PROGRAM_ARB );
VertexOnly_ID.Bind();
SetShaderMatrix(ACTUAL_MODEL, shadowView, ACTUAL_PROJECTION);

village->DrawSimpleModel();

glDisable( GL_VERTEX_PROGRAM_ARB );


		glReadBuffer(GL_DEPTH_BUFFER_BIT);
		glBindTexture(GL_TEXTURE_2D, shadowtex);
		glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1024, 512);
//depth tex copied

glActiveTextureARB(GL_TEXTURE0_ARB);

glClear(GL_COLOR_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT);


glEnable(GL_TEXTURE_2D);

glEnable( GL_VERTEX_PROGRAM_ARB );
glEnable( GL_FRAGMENT_PROGRAM_ARB );

SHADOW_SHADER.Bind();

SetShaderMatrix(ACTUAL_MODEL, ACTUAL_VIEW, ACTUAL_PROJECTION);

Matrix44<double> biasmvp;
biasmvp.LoadBiasIdentity();

Matrix44<double> SMVP = ((ACTUAL_MODEL * shadowView) * ACTUAL_PROJECTION)*biasmvp;

SendMatrixToShader(SMVP, 5);

village->DrawSimpleModel();

glDisable( GL_FRAGMENT_PROGRAM_ARB );
glDisable( GL_VERTEX_PROGRAM_ARB );
glDisable(GL_TEXTURE_2D);
}}

now things will be messy shaders! 

 

 

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

!!ARBvp1.0


PARAM MVP1 = program.local[1];
PARAM MVP2 = program.local[2];
PARAM MVP3 = program.local[3];
PARAM MVP4 = program.local[4];


PARAM SMVP1 = program.local[5];
PARAM SMVP2 = program.local[6];
PARAM SMVP3 = program.local[7];
PARAM SMVP4 = program.local[8];

#compute vertex position
TEMP vertexClip;
DP4 vertexClip.x, MVP1, vertex.position;
DP4 vertexClip.y, MVP2, vertex.position;
DP4 vertexClip.z, MVP3, vertex.position;
DP4 vertexClip.w, MVP4, vertex.position;

#computre vertex in light space position
TEMP shadowClip;
DP4 shadowClip.x, SMVP1, vertex.position;
DP4 shadowClip.y, SMVP2, vertex.position;
DP4 shadowClip.z, SMVP3, vertex.position;
DP4 shadowClip.w, SMVP4, vertex.position;

#set color as rgb 1,1,1,1
TEMP COL;
MOV COL.x, 1.0;
MOV COL.y, 1.0;
MOV COL.z, 1.0;
MOV COL.w, 1.0;
MOV result.color, COL;

#send vertex pos to oglpipeline
MOV result.position, vertexClip;
#texture coords untouched
MOV result.texcoord[0], vertex.texcoord;

#send vertex position in light view to fragment
MOV result.texcoord[2].x, shadowClip.x;
MOV result.texcoord[2].y, shadowClip.y;
MOV result.texcoord[3].x, shadowClip.z;
MOV result.texcoord[3].y, shadowClip.w;

END

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fragment shader:

!!ARBfp1.0

TEMP ShadowDEPTH;
#get the data we send to fragment shader
TEMP ShadowClip;
MOV ShadowClip.x, fragment.texcoord[2].x;
MOV ShadowClip.y, fragment.texcoord[2].y;
MOV ShadowClip.z, fragment.texcoord[3].x;
MOV ShadowClip.w, fragment.texcoord[3].y;


TEMP W_DIV;
#Make W_DIV.x = 1.0 / ShadowClip.w;
RCP W_DIV.x, ShadowClip.w; 

# shadowclip.z = shadowclip.z / shadowclip.w;
MUL ShadowClip.z, ShadowClip.z, W_DIV.x;




#make a 2d point for texture sampling just to be sure
TEMP ShadowCoord;
MOV ShadowCoord.x, ShadowClip.x;
MOV ShadowCoord.y, ShadowClip.y;
MOV ShadowCoord.z, 0.0;
MOV ShadowCoord.w, 1.0;

#take texture sample out of ShadowCoord x and y
TEX ShadowDEPTH, ShadowCoord, texture[1], 2D;

#add offset
ADD ShadowDEPTH.x, ShadowDEPTH.x, 0.0000625;
MAX ShadowDEPTH.x, ShadowDEPTH.x, 0.0;
MIN ShadowDEPTH.x, ShadowDEPTH.x, 1.0;



TEMP dRES;
#compute if we are in shadow by subtracting Depth_FROM_TEX - Vertex_in_shadow.z
SUB dRES.x, ShadowDEPTH.x, ShadowClip.z;

#if its smaller than 0 clamp it to 0
MAX dRES.x, dRES.x, 0.0;
#if its bigger than 0 multiple it y a big number and then clamp to 1  to get 1
MUL dRES.x, dRES.x, 100000.0;
MIN dRES.x, 1.0, dRES.x;

#output the color
MOV result.color.r, dRES.x;
MOV result.color.g, dRES.x;
MOV result.color.b, dRES.x;
MOV result.color.a, 1.0;

END

 

==================================================================================================================

 

 

 

Again results

 

LIGHT POV

s1.jpg

 

 

camera pov

 

 

s2.jpg

 

 

 

 

 

 

 

 

another shot from cam pov

 

 

s3.jpg


PARTNERS