Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your help!

We need 7 developers from Canada and 18 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a $50 Amazon gift card. Click here to get started!


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);
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;
OUT.LightVec = lightDir - Pw;
OUT.LightVec = lightDir;

OUT.UV = float2((1.0-IN.UV.x),(1.0-IN.UV.y));
OUT.UV = float2(IN.UV.x,(1.0-IN.UV.y));
OUT.UV = float2((1.0-IN.UV.x),IN.UV.y);
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;

/* 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++){

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++)
phong.Shader->SetTexture("ColorTexture", objects[i2].diffuse[i]);
phong.Shader->SetTexture("SpecTexture", objects[i2].specular[i]);
phong.Shader->SetTexture("NormTexture", objects[i2].normal[i]);



The projection matrix is set with this:
void PD_RENDERER::SetFOV(float FOV){
D3DXMATRIX matProjection;
(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]