Jump to content
  • Advertisement
Sign in to follow this  

light problem

This topic is 2571 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi guys

i am learning lighting with directx.I coded a applicationto implement directional light.but when i changed teapot face direction from (0.0f,0.0f,1.0f) to (0.0f,0.0f,-1.0f) .there are something wrong with my application.

face = (0.0f,0.0f,1.0f)

face = (0.0f,0.0f,-1.0f)

this is partial code:

material.ambient = material.diffuse = material.specular = D3DXCOLOR(1.0f,1.0f,1.0f,1.0f);

SFMATERIAL material;
D3DXVECTOR3 position;
D3DXVECTOR3 right;

_SFC3DObject::_SFC3DObject(SF3DOBJECTSTATE* objectState):m_3DObjectState(*objectState)
m_worldMatrix(0,0) = m_3DObjectState.right.x; m_worldMatrix(0, 1) = m_3DObjectState.right.y; m_worldMatrix(0, 2) = m_3DObjectState.right.z; m_worldMatrix(0, 3) = 0.0f;
m_worldMatrix(1,0) = m_3DObjectState.up.x; m_worldMatrix(1, 1) = m_3DObjectState.up.y; m_worldMatrix(1, 2) = m_3DObjectState.up.z; m_worldMatrix(1, 3) = 0.0f;
m_worldMatrix(2,0) = m_3DObjectState.face.x; m_worldMatrix(2, 1) = m_3DObjectState.face.y; m_worldMatrix(2, 2) = m_3DObjectState.face.z; m_worldMatrix(2, 3) = 0.0f;
m_worldMatrix(3,0) = m_3DObjectState.position.x; m_worldMatrix(3, 1) = m_3DObjectState.position.y; m_worldMatrix(3, 2) = m_3DObjectState.position.z; m_worldMatrix(3, 3) = 1.0f;


D3DXCOLOR ambient;
D3DXCOLOR diffuse;
D3DXCOLOR specular;


D3DXVECTOR3 direction;

this is my effect code:

uniform extern float4x4 gWorld;
uniform extern float4x4 gWorldInverseTranspose;
uniform extern float4x4 gWVP;

uniform extern float4 gAmbientMtrl;
uniform extern float4 gAmbientLight;
uniform extern float4 gDiffuseMtrl;
uniform extern float4 gDiffuseLight;
uniform extern float4 gSpecularMtrl;
uniform extern float4 gSpecularLight;
uniform extern float gSpecularPower;
uniform extern float3 gLightVecW;
uniform extern float3 gEyePosW;

struct OutputVS
float4 posH : POSITION0;
float4 color : COLOR0;

OutputVS AmbientDiffuseSpecVS(float3 posL : POSITION0, float3 normalL : NORMAL0)
// Zero out our output.
OutputVS outVS = (OutputVS)0;

// Transform normal to world space.
float3 normalW = mul(float4(normalL, 0.0f), gWorldInverseTranspose).xyz;
normalW = normalize(normalW);

// Transform vertex position to world space.
float3 posW = mul(float4(posL, 1.0f), gWorld).xyz;

// Compute the color: Equation 10.3.

// Compute the vector from the vertex to the eye position.
float3 toEye = normalize(gEyePosW - posW);

// Compute the reflection vector.
float3 r = reflect(-gLightVecW, normalW);

// Determine how much (if any) specular light makes it into the eye.
float t = pow(max(dot(r, toEye), 0.0f), gSpecularPower);

// Determine the diffuse light intensity that strikes the vertex.
float s = max(dot(gLightVecW, normalW), 0.0f);

// Compute the ambient, diffuse and specular terms separatly.
float3 spec = t*(gSpecularMtrl*gSpecularLight).rgb;
float3 diffuse = s*(gDiffuseMtrl*gDiffuseLight).rgb;
float3 ambient = gAmbientMtrl*gAmbientLight;

// Sum all the terms together and copy over the diffuse alpha.
outVS.color.rgb = ambient + diffuse + spec;
outVS.color.a = gDiffuseMtrl.a;

// Transform to homogeneous clip space.
outVS.posH = mul(float4(posL, 1.0f), gWVP);

// Done--return the output.
return outVS;

float4 AmbientDiffuseSpecPS(float4 c : COLOR0) : COLOR
return c;

technique AmbientDiffuseSpecTech
pass P0
// Specify the vertex and pixel shader associated with this pass.
vertexShader = compile vs_2_0 AmbientDiffuseSpecVS();
pixelShader = compile ps_2_0 AmbientDiffuseSpecPS();

any help is appreciated

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!