Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Light position problem


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
20 replies to this topic

#1 lyzerk   Members   -  Reputation: 120

Like
0Likes
Like

Posted 05 September 2012 - 12:33 PM

Hello,

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.

Sponsor:

#2 Seabolt   Members   -  Reputation: 633

Like
1Likes
Like

Posted 05 September 2012 - 03:01 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.
Perception is when one imagination clashes with another

#3 lyzerk   Members   -  Reputation: 120

Like
0Likes
Like

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 kauna   Crossbones+   -  Reputation: 2832

Like
0Likes
Like

Posted 06 September 2012 - 06:59 AM

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!

#5 lyzerk   Members   -  Reputation: 120

Like
0Likes
Like

Posted 06 September 2012 - 09:36 AM

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!

float4(1.0f,1.0f,1.0f,1.0f) its worked all screen gonna white.

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 ) );

#6 kauna   Crossbones+   -  Reputation: 2832

Like
0Likes
Like

Posted 06 September 2012 - 09:48 AM

What is your LIGHT_FALLOFF value?

Also, your light position is at -100,-100,-100. Isn't that underground?

Best regards!

Edited by kauna, 06 September 2012 - 09:49 AM.


#7 lyzerk   Members   -  Reputation: 120

Like
0Likes
Like

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 kauna   Crossbones+   -  Reputation: 2832

Like
0Likes
Like

Posted 06 September 2012 - 10:43 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!

#9 lyzerk   Members   -  Reputation: 120

Like
0Likes
Like

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

#10 kauna   Crossbones+   -  Reputation: 2832

Like
0Likes
Like

Posted 06 September 2012 - 11:45 AM

Just one question more : why do you set StencilEnable to Enable for the second pass?

Best regards!

#11 lyzerk   Members   -  Reputation: 120

Like
0Likes
Like

Posted 06 September 2012 - 11:50 AM

Just one question more : why do you set StencilEnable to Enable for the second pass?

Best regards!

I didn't, like i said its copy from one working project. Maybe i need to Transform vector ?

Edited by lyzerk, 06 September 2012 - 11:50 AM.


#12 kauna   Crossbones+   -  Reputation: 2832

Like
0Likes
Like

Posted 06 September 2012 - 11:55 AM

So wait, is the technique descriptions in the first post the same as you are using now? The text you wrote in the first message clearly states that you have enabled stencil testing for the second pass.

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.


#13 lyzerk   Members   -  Reputation: 120

Like
0Likes
Like

Posted 06 September 2012 - 12:06 PM

yes its same i tried delete it and false,true it but still same result. what it should be ? but i think problem is light vector

#14 BCullis   Crossbones+   -  Reputation: 1813

Like
0Likes
Like

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.
Hazard Pay :: FPS/RTS in SharpDX
DeviantArt :: Because right-brain needs love too

#15 kauna   Crossbones+   -  Reputation: 2832

Like
0Likes
Like

Posted 06 September 2012 - 12:35 PM

You can also set your light vector value manually to something like 0,0,1 to see quickly if it has some effect.

Cheers!

#16 lyzerk   Members   -  Reputation: 120

Like
0Likes
Like

Posted 06 September 2012 - 12:57 PM

Ok now i open PIX and trying to use. but i think problem isnt light color or something. i think problem is that lightView here;

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 kauna   Crossbones+   -  Reputation: 2832

Like
0Likes
Like

Posted 06 September 2012 - 01:12 PM

GPU's handle vectors in size of 4 so for that reason you won't find a function to set a 3-component vector. Don't worry about it, the 4 component vector contains the 3-component vectors information and the 4-value is just left 0. Anyway, you'll need to give a 4-component vector to the function, otherwise you may end up having some undefined behaviour.

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 lyzerk   Members   -  Reputation: 120

Like
0Likes
Like

Posted 06 September 2012 - 03:56 PM

hmm i understand i did same as they did but everything is same, nothings working. im really tried about that HLSL light. if someone can fix this i uploaded my project and worked project

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.


#19 lyzerk   Members   -  Reputation: 120

Like
0Likes
Like

Posted 07 September 2012 - 09:59 AM

can anyone help ?

#20 kauna   Crossbones+   -  Reputation: 2832

Like
0Likes
Like

Posted 07 September 2012 - 10:28 AM

Are you sure that you want to go on with this? I don't want to be discouraging, but it seems that most of the things you have shown are way over your skills. Fixing one problem will just lead to another problem.

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!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS