#1 Members - Reputation: 120
Posted 05 September 2012 - 12:33 PM
I have problem with light pos, I did one HLSL file here technique
[source lang="cpp"]technique RenderDarkAtmospher{ pass P0 { VertexShader = compile vs_2_0 VertSceneAmbient(); PixelShader = compile ps_2_0 PixSceneAmbient(); StencilEnable = false; ZFunc = LessEqual; } pass P1 { VertexShader = compile vs_2_0 VertScene(); PixelShader = compile ps_2_0 PixScene(); ZEnable = true; ZFunc = LessEqual; StencilEnable = true; AlphaBlendEnable = true; BlendOp = Add; SrcBlend = One; DestBlend = One; StencilRef = 1; StencilFunc = Greater; StencilPass = Keep; }}[/source]
anyway my HLSL functions is correct, i copy it from working one project. pass p0 is working great all terrain going a black Atmospher, but i tryed a values for light pos but itsnt worked. I want camera with light.
PixScene :
[source lang="cpp"] float3 L = g_vLightView - ViewPos; float LenSq = dot( L, L ); L = normalize( L ); // Compute lighting amount float4 I = saturate( dot( normalize( ViewNormal ), L ) ) * Diffuse * (LIGHT_FALLOFF * LIGHT_FALLOFF) / LenSq; // Lookup mesh texture and modulate it with diffuse return float4( tex2D( g_samScene, Tex0 ).xyz, 1.0f ) * I;[/source]
and my camera matrixes
[source lang="cpp"] D3DXMATRIXA16 matWorld; D3DXMatrixTranslation( &matWorld, camera.camera.x, camera.camera.y, camera.camera.z); D3DXVECTOR3 vEyePt( 0, 100, 0 ); D3DXVECTOR3 vLookatPt( 0 , 0, camera.vec ); D3DXVECTOR3 vUpVec( 0, 1, 1 ); //up D3DXMATRIXA16 matView; D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec ); D3DXMATRIXA16 result = matWorld * matView; pd3dDevice->SetTransform( D3DTS_VIEW, &result ); D3DXMATRIXA16 matProj; D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI / 4, 1.0f, 1.0f, 1000.0f ); pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );[/source]
[source lang="cpp"] D3DXVECTOR3 vLight( -100, -100, -100); id3dxEffect->SetValue( id3dxEffect->GetParameterByName(NULL, "g_vLightView"), &vLight, sizeof(vLight) );[/source]
What i should do for light pos ? nothings apper
Thanks.
#3 Members - Reputation: 120
Posted 05 September 2012 - 03:23 PM
I would take it into pix and see what the value of g_vLightView, otherwise it would be hard to pin-point what exactly the issue is.
[source lang="java"]float3 g_vLightView;[/source]
its float3 and here ps and vs functions
[source lang="cpp"]void VertScene( float4 vPos : POSITION, float3 vNormal : NORMAL, float2 vTex0 : TEXCOORD0, out float4 oPos : POSITION, out float4 ViewPos : TEXCOORD0, out float3 ViewNormal : TEXCOORD1, out float2 oTex0 : TEXCOORD2, out float4 oDiffuse : TEXCOORD3 ){ // Transform the position from view space to homogeneous projection space oPos = mul( vPos, g_mWorldViewProjection ); // Compute view space position ViewPos = mul( vPos, g_mWorldView ); // Compute world space normal ViewNormal = normalize( mul( vNormal, (float3x3)g_mWorldView ) ); // Modulate material with light to obtain diffuse oDiffuse = g_vMatColor * g_vLightColor; // Just copy the texture coordinate through oTex0 = vTex0;}float4 PixScene( float4 ViewPos : TEXCOORD0, float3 ViewNormal : TEXCOORD1, float2 Tex0 : TEXCOORD2, float4 Diffuse : TEXCOORD3 ) : COLOR0{ // Pixel to light vector float3 L = g_vLightView - ViewPos; float LenSq = dot( L, L ); L = normalize( L ); // Compute lighting amount float4 I = saturate( dot( normalize( ViewNormal ), L ) ) * Diffuse * (LIGHT_FALLOFF * LIGHT_FALLOFF) / LenSq; // Lookup mesh texture and modulate it with diffuse return float4( tex2D( g_samScene, Tex0 ).xyz, 1.0f ) * I;}[/source]
#4 Members - Reputation: 1132
Posted 06 September 2012 - 06:59 AM
Cheers!
#5 Members - Reputation: 120
Posted 06 September 2012 - 09:36 AM
float4(1.0f,1.0f,1.0f,1.0f) its worked all screen gonna white.Well you could output just float4(1.0f,1.0f,1.0f,1.0f) from your shader if nothing appears. Just to verify that your code works. Also, you could set the background clear color to something else than black to verify if something is being drawed.
Cheers!
and i did clear screen before begin with that
V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_STENCIL, D3DCOLOR_ARGB( 0, 170, 170, 170 ), 1.0f, 0 ) );
#7 Members - Reputation: 120
Posted 06 September 2012 - 10:12 AM
What is your LIGHT_FALLOFF value?
Also, your light position is at -100,-100,-100. Isn't that underground?
Best regards!
LIGHT_FALLOF is 1.4
its my camera position. its not wrong i think.
-Thanks
Edited by lyzerk, 06 September 2012 - 10:30 AM.
#8 Members - Reputation: 1132
Posted 06 September 2012 - 10:43 AM
// Compute world space normal
ViewNormal = normalize( mul( vNormal, (float3x3)g_mWorldView ) );
The code above looks suspicious in the sense that you write "Compute world space normal" but actually you are calculating view space normals. Are you doing all your calculations in the same space?
Cheers!
#9 Members - Reputation: 120
Posted 06 September 2012 - 10:59 AM
Well, have you tried to play with the light_falloff value? Have you tried to narrow down the problem, like simplifying your intensity formula.
// Compute world space normal
ViewNormal = normalize( mul( vNormal, (float3x3)g_mWorldView ) );
The code above looks suspicious in the sense that you write "Compute world space normal" but actually you are calculating view space normals. Are you doing all your calculations in the same space?
Cheers!
Yes i tried play with light_falloff value negative and positive, i dont think so functions is wrong because i copy it from working one project. but they doing it like this;
[source lang="cpp"] D3DXVECTOR4 vLight( g_aLights[L].m_Position.x, g_aLights[L].m_Position.y, g_aLights[L].m_Position.z, 1.0f ); D3DXVec4Transform( &vLight, &vLight, g_LCamera.GetWorldMatrix() ); D3DXVec4Transform( &vLight, &vLight, g_Camera.GetViewMatrix() ); V( g_pEffect->SetVector( "g_vLightView", &vLight ) );[/source]
problem is just GetWorldMatrix and GetViewMatrix their return is matrix not matrix16, my Matrixes is matrix16, i can't figure out.
-Thanks
#11 Members - Reputation: 120
Posted 06 September 2012 - 11:50 AM
I didn't, like i said its copy from one working project. Maybe i need to Transform vector ?Just one question more : why do you set StencilEnable to Enable for the second pass?
Best regards!
Edited by lyzerk, 06 September 2012 - 11:50 AM.
#12 Members - Reputation: 1132
Posted 06 September 2012 - 11:55 AM
technique RenderDarkAtmospher
{
pass P0
{
VertexShader = compile vs_2_0 VertSceneAmbient();
PixelShader = compile ps_2_0 PixSceneAmbient();
StencilEnable = false;
ZFunc = LessEqual;
}
pass P1
{
VertexShader = compile vs_2_0 VertScene();
PixelShader = compile ps_2_0 PixScene();
ZEnable = true;
ZFunc = LessEqual;
StencilEnable = true;
AlphaBlendEnable = true;
BlendOp = Add;
SrcBlend = One;
DestBlend = One;
StencilRef = 1;
StencilFunc = Greater;
StencilPass = Keep;
}
}
[Edit] I guess that the stencil doesn't affect your output. But I'd look into the code a bit closer for not to just copy things blindly.
Edited by kauna, 06 September 2012 - 12:04 PM.
#14 Members - Reputation: 1671
Posted 06 September 2012 - 12:32 PM
I would take it into pix and see what the value of g_vLightView
its float3
Are you familiar with the PIX debugging tool? That's what Seabolt is referring to. It comes bundled with the DirectX SDK. Look at a frame in the PIX debugger and see what the actual value (not type) of g_vLightView is being set to.
#16 Members - Reputation: 120
Posted 06 September 2012 - 12:57 PM
at HLSL lightView is float3 and he is using ->SetVector. SecVector is for float4, and vLight is vector4. its so weird :S
and he is transform vLight with matrix. maybe i should do ? but my matrixes "matrix16" not "matrix" so i dont know how to do.
Sorry for my english, i'm trying for best.
-Thanks
#17 Members - Reputation: 1132
Posted 06 September 2012 - 01:12 PM
If you have 2 matrices of the same size but different type, there is no reason that you may copy all the elements from one to another.
Otherwise _D3DXMATRIXA16 is derived from D3DXMATRIX, so any function accepting D3DXMATRIX will accept also _D3DXMATRIXA16.
Cheers!
#18 Members - Reputation: 120
Posted 06 September 2012 - 03:56 PM
EmptyProject.rar is my project, and ShadowVolume is from directxsampler i copy everything about HSLS light. if someone worked light on EmptyProject, i will so much grateful
-Thanks for everthing.
Attached Files
Edited by lyzerk, 06 September 2012 - 03:57 PM.
#20 Members - Reputation: 1132
Posted 07 September 2012 - 10:28 AM
Have you considered using something a bit more easier for starting your graphics / game programming career? There are plenty of engine frameworks available which will give you the chance to focus on something productive instead of fighting with a single problem for days.
Beat regards!







