• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
lyzerk

Light position problem

20 posts in this topic

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.
0

Share this post


Link to post
Share on other sites
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.
1

Share this post


Link to post
Share on other sites
[quote name='Seabolt' timestamp='1346878885' post='4976978']
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.
[/quote]

[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]
0

Share this post


Link to post
Share on other sites
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!
0

Share this post


Link to post
Share on other sites
[quote name='kauna' timestamp='1346936343' post='4977169']
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!
[/quote]
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 ) );
0

Share this post


Link to post
Share on other sites
What is your LIGHT_FALLOFF value?

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

Best regards! Edited by kauna
0

Share this post


Link to post
Share on other sites
[quote name='kauna' timestamp='1346946498' post='4977242']
What is your LIGHT_FALLOFF value?

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

Best regards!
[/quote]

LIGHT_FALLOF is 1.4
its my camera position. its not wrong i think.

-Thanks Edited by lyzerk
0

Share this post


Link to post
Share on other sites
Well, have you tried to play with the light_falloff value? Have you tried to narrow down the problem, like simplifying your intensity formula.

[quote]
// Compute world space normal
ViewNormal = normalize( mul( vNormal, (float3x3)g_mWorldView ) );
[/quote]

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!
0

Share this post


Link to post
Share on other sites
[quote name='kauna' timestamp='1346949792' post='4977263']
Well, have you tried to play with the light_falloff value? Have you tried to narrow down the problem, like simplifying your intensity formula.

[quote]
// Compute world space normal
ViewNormal = normalize( mul( vNormal, (float3x3)g_mWorldView ) );
[/quote]

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!
[/quote]

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
0

Share this post


Link to post
Share on other sites
Just one question more : why do you set StencilEnable to Enable for the second pass?

Best regards!
0

Share this post


Link to post
Share on other sites
[quote name='kauna' timestamp='1346953508' post='4977279']
Just one question more : why do you set StencilEnable to Enable for the second pass?

Best regards!
[/quote]
I didn't, like i said its copy from one working project. Maybe i need to Transform vector ? Edited by lyzerk
0

Share this post


Link to post
Share on other sites
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.

[quote]
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;
[b] StencilEnable = true;[/b]
AlphaBlendEnable = true;
BlendOp = Add;
SrcBlend = One;
DestBlend = One;
StencilRef = 1;
StencilFunc = Greater;
StencilPass = Keep;
}
}
[/quote]

[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
0

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites
[quote name='Seabolt' timestamp='1346878885' post='4976978']
I would take it into pix and see what the value of g_vLightView
[/quote]
[quote name='lyzerk' timestamp='1346880219' post='4976987']
its float3
[/quote]

Are you familiar with the [url="http://en.wikipedia.org/wiki/PIX_(Microsoft)"]PIX[/url] 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.
0

Share this post


Link to post
Share on other sites
You can also set your light vector value manually to something like 0,0,1 to see quickly if it has some effect.

Cheers!
0

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites
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!
0

Share this post


Link to post
Share on other sites
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. Edited by lyzerk
0

Share this post


Link to post
Share on other sites
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!
0

Share this post


Link to post
Share on other sites
Ok,

I took a look into your project.

There were several problems:

- some of them preventing the light source from creating lighting effect.
- one which crashes the program under debug builds.

The errors are:

- Your vertex format doesn't have normals in them. For some reason you have commented out the normals. Actually your vertex format isn't the same on the program side and on the HLSL side. Fix this. You need the normals and the format has to be same in the program side and HLSL side. You can't expect the calculations to make sense if the input values aren't defined. Normals in this case aren't defined. You'll need to change the FVF declaration to include the normals.

- Your lighting calculation uses "Diffuse" multiplier. I didn't look into it so closely, but it seems to be 0 or close to it. Multiplying anything with 0 results 0 = black.

- Spaces : some of your values are in view space and some are in world space. Mixing those values won't give you correct result. Ie. Light position in world space and vertex position in view space.

- You are clearing the screen twice. It crashes the program because of invalid parameters or so. What is it with the stencil? Where do you need the stencil buffer?

Most of these things could have been debugged quite easily such as :
- use PIX
- narrow down the problem - split complex calculations/functions in parts and inspect each of them separately to find out parts which don't behave as intended.
- make the pixel shader output the value your want to inspect (this way I noticed that your normals are missing)
- Use debug builds and D3D debug libraries to catch invalid function calls.

Best regards! Edited by kauna
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0