Jump to content

  • Log In with Google      Sign In   
  • Create Account


JezzaP

Member Since 27 May 2009
Offline Last Active Nov 26 2013 04:15 AM
-----

Posts I've Made

In Topic: [C++] DirectInput Hooking component and sample

03 January 2012 - 08:00 AM

does anyone have a local copy of this sample? I really would like to see it but the link is dead.

In Topic: check if released

21 July 2009 - 08:14 PM

Thanks, I never of the existence of such classes. That's a real help.

In Topic: texture coordinates mess up

29 May 2009 - 01:22 AM

Can anyone see the problem in this code? Or want to see more?

EDIT: How strange. I upgraded to the latest dx version (March, I was using November 08) and it works. I also changed all the shaders to model 2 instead of 3. One of those made it work. Ah well.

[Edited by - JezzaP on May 29, 2009 8:22:02 AM]

In Topic: texture coordinates mess up

28 May 2009 - 01:06 AM

Ok here is my vertex shader:
vertexOutput std_VS(appdata IN) {
vertexOutput OUT = (vertexOutput)0;
OUT.WorldNormal = normalize(mul(IN.Normal,WorldITXf).xyz);
if(useNorm){
OUT.WorldTangent = normalize(mul(IN.Tangent,WorldITXf).xyz);
OUT.WorldBinormal = normalize(mul(IN.Binormal,WorldITXf).xyz);
}
float4 Po = float4(IN.Position.xyz,1);
float3 Pw = mul(Po,WorldXf).xyz;
if(1==lightType){
OUT.LightVec = lightDir - Pw;
}else
OUT.LightVec = lightDir;

if(flipy){
if(flipx)
OUT.UV = float2((1.0-IN.UV.x),(1.0-IN.UV.y));
else
OUT.UV = float2(IN.UV.x,(1.0-IN.UV.y));
}
else{
if(flipx)
OUT.UV = float2((1.0-IN.UV.x),IN.UV.y);
else
OUT.UV = float2(IN.UV.x,IN.UV.y);
}

OUT.WorldView = normalize(ViewIXf[3].xyz - Pw);
OUT.HPosition = mul(Po,WvpXf);

return OUT;
}



Where the matrices are:
float4x4 WorldITXf : WorldInverseTranspose;
float4x4 WvpXf : WorldViewProjection;
float4x4 WorldXf : World;
float4x4 Projection : Projection;
float4x4 ViewIXf : ViewInverse;
float4x4 WorldIXf : WorldInverse;



structs:
/* data from application vertex buffer */
struct appdata {
float3 Position : POSITION;
float4 UV : TEXCOORD0;
float4 Normal : NORMAL;
float4 Tangent : TANGENT;
float4 Binormal : BINORMAL;
};

/* data passed from vertex shader to pixel shader */
struct vertexOutput {
float4 HPosition : POSITION;
float2 UV : TEXCOORD0;
float3 WorldNormal : TEXCOORD2;
float3 WorldTangent : TEXCOORD3;
float3 WorldBinormal : TEXCOORD4;
float3 WorldView : TEXCOORD1;
float3 LightVec : TEXCOORD5;
float3 Attenuation : TEXCOORD6;
};



The samplers all look like this:
sampler ColorSampler = sampler_state { 
texture = <ColorTexture> ;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = WRAP;
AddressV = WRAP;
AddressW = WRAP;
};



The matrices are set like this:
sys->Device->GetTransform(D3DTS_VIEW, &matView);
sys->Device->GetTransform(D3DTS_PROJECTION, &matProjection);

D3DXMatrixInverse(&matInverseView, NULL, &matView);

matWorld = new D3DXMATRIX[numObjects];
matWorldViewProjection = new D3DXMATRIX[numObjects];
matWorldView = new D3DXMATRIX[numObjects];
matWorldInverseTransponse = new D3DXMATRIX[numObjects];
matWorldInverse = new D3DXMATRIX[numObjects];

phong.Shader->SetMatrix("ViewIXf", &matInverseView);

for(int i2=0; i2<numObjects; i2++){
matWorld[i2]=objects[i2].pose;

D3DXMatrixMultiply(&matWorldView[i2], &matWorld[i2], &matView);

D3DXMatrixMultiply(&matWorldViewProjection[i2], &matWorldView[i2], &matProjection);

D3DXMatrixInverse(&matWorldInverse[i2], NULL, &matWorld[i2]);
D3DXMatrixTranspose(&matWorldInverseTransponse[i2], &matWorldInverse[i2]);
}



objects are then rendered like this:
for(int i2=0; i2<numObjects; i2++){	
//set variables for shader
phong.Shader->SetMatrix("WorldXf", &matWorld[i2]);
phong.Shader->SetMatrix("WorldITXf", &matWorldInverseTransponse[i2]);
phong.Shader->SetMatrix("WvpXf", &matWorldViewProjection[i2]);

for(DWORD i = 0; i < objects[i2].numMaterials; i++)
{
if(objects[i2].diffuse[i]!=NULL)
phong.Shader->SetTexture("ColorTexture", objects[i2].diffuse[i]);
if(objects[i2].specular[i]!=NULL)
phong.Shader->SetTexture("SpecTexture", objects[i2].specular[i]);
if(objects[i2].normal[i]!=NULL)
phong.Shader->SetTexture("NormTexture", objects[i2].normal[i]);
phong.Shader->CommitChanges();

objects[i2].DXObject->DrawSubset(i);
}

}



The projection matrix is set with this:
void PD_RENDERER::SetFOV(float FOV){
D3DXMATRIX matProjection;
D3DXMatrixPerspectiveFovLH(&matProjection,
pdDegree2Rad(FOV),
(FLOAT)ScreenWidth / (FLOAT)ScreenHeight,
0.1f, 500.0f );

matProjection(2,2) = 1.0f;
matProjection(3,2) = -1.0f;

sys->Device->SetTransform(D3DTS_PROJECTION, &matProjection);
}



where float FOV defaults to 45 (which is what I use)

[Edited by - JezzaP on May 29, 2009 1:06:18 AM]

PARTNERS