The Light.Count accuratly reports the correct number of lights during run
time and yes, RenderState.Lighting is set to true. A material is also setup.
The odd thing is that Microsoft's framework does not mention lighting, yet,
loaded models have an ambient light.
I am assuming that the framework is rendering the basic colors of the
vertices and mimicing a RenderState.Lighting = false scenario.
How do I change this, so that I can view my lights?
For reference use CustomUI in the DX9c SDK.
Quote for Today: 'At least I know my a** from a VertexBuffer.'
Is your light pointing at the model?
Are you looking at the right side of your model?
Did you set a drop off distance for the light and then put it too far away.
Lights do work with the sample framework. Try the initial state of my
Coding4Fun article from here
http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=89812117-2b35-44b9-80bd-4b1e09909b60
It has a mesh.box, some ambient and (I think) a single directional light.
--
Zman (mailto:zm...@thezbuffer.com)
http://www.thezbuffer.com
News and Resources for Managed DirectX
"Moo Mansun" <urlo...@nothing.com> wrote in message
news:058db9b869e94e70...@ureader.com...
Here is the scenario:
If you start up Microsoft's default CustomUI, we can start from there.
1. The scene is lit, although no ambient light source is set.
Is it processing the vertex colors only? (i.e. the same as renderstate.
lighting = false)
2. How do I modify it so that the ambient light disappears and the scene
reacts to my lights?
3. Do I need to write additional code for processing lighting calculations?
The mesh is processed from dxmutmesh.cs and the renderstates set from
dxmutgui.cs.
Remember I am creating an instance of FrameworkMesh as the loading mechanism.
So I would reference something like mesh.localmesh or mesh.
systemmemorymesh.
I examined your code and DumpInfo() looks very close, but I think this is
done by the FrameworkMesh in dxmutmesh.cs.
Perhaps the best way to approach this is to create some form of checklist
covering the pipeline, a DX Pipeline Overview from the perspective of a 3D
Engine.
It would certainly assist not only newcomers but serve as an everyday
practical tool for developers. Written in plain english, with samples for
each aspect of the pipeline, then we wouldn't have the scenario of people
not knowing of certain commands or basic/full steps to implement a feature.
By insisting on classes, in a seperate file, for samples, we could make the
whole thing drag and drop essentially.
Thank Z.
.localmesh and .systemmesh are just Mesh objects the same as I create .box
in the sample. dumpmesh() is purely a helper function to read vertices so
I'm not sure why you think that is helpful.
What you are asking for is enough to fill a book. Maybe one day I will
consider writing one, but for now I can jsut suggest you start with Tom's
book and go from there.
It is indeed unfortunate that there are no docs for the dxframework but
thats the way it is. 3d programming is a tough beast to crack, you have to
just keep digging in until bits of start to make sense.
--
Zman (mailto:zm...@thezbuffer.com)
http://www.thezbuffer.com
News and Resources for Managed DirectX
"Moo Mansun" <urlo...@nothing.com> wrote in message
news:56d6ade292ab40f0...@ureader.com...
I'm asking where the light is coming from in that sample?
Not really books worth...
Your sample bypasses the frameworkMesh and most and is basically a modified
version of the teapot example.
Any straight answers?
void VertScene( float4 Pos : POSITION,float2 Tex : TEXCOORD0,out float4 oPos
: POSITION,out float2 oTex : TEXCOORD0 )
{
oPos = mul( Pos, worldViewProjection );
oTex = Tex;
}
float4 PixScene( float2 Tex : TEXCOORD0 ) : COLOR0
{
return tex2D( g_samScene, Tex );
}
Basically this shader just says the color of the final pixel is the color of
the texture. Its the same as having white ambient lighting. If you were to
render your mesh inside the same shader, and it has texture coordinates then
you should see the same thng. If you have no texture coordinates then you
will see black since nothing but the texture is taken into account.
To draw objects using the fixed function then set up your lighting (as per
my sample, there really is no difference between how you set up the lights
for a Mesh or a .frameworkMesh) and make sure your draw calls are NOT inside
the effect.Begin, effect.End block of code, but still inside the
.BeginScene, .EndSceneBlock.
The following would be the 'book' I mentioned......
>Perhaps the best way to approach this is to create some form of checklist
>covering the pipeline, a DX Pipeline Overview from the perspective of a 3D
>Engine. It would certainly assist not only newcomers but serve as an
>everyday
>practical tool for developers. Written in plain english, with samples for
>each aspect of the pipeline, then we wouldn't have the scenario of people
>not knowing of certain commands or basic/full steps to implement a feature.
--
Zman (mailto:zm...@thezbuffer.com)
http://www.thezbuffer.com
News and Resources for Managed DirectX
"Moo Mansun" <urlo...@nothing.com> wrote in message
news:cb0129ea974f44bc...@ureader.com...
Basically, the shader is just outputing the normal texture colors to a
specific co-ordinate. If I have this right, the sample application passes
the texture to the .fx file, which in turn, processes the texture directly
in the GPU. By then calling DrawSubset(i) we then draw that modified
texture.
I can now see the benefits of HLSL, very fast.
Two questions now arise:
1. How do we modify the code (see below) to remove the ambient lighting
effect?
2. How do we modify the code to account for the effects of a single light?
(I'd like to do this in HLSL, speed)
The code of CustomUI.fx
void VertScene( float4 Pos : POSITION,float2 Tex : TEXCOORD0,out float4 oPos
: POSITION,out float2 oTex : TEXCOORD0 )
{
oPos = mul( Pos, worldViewProjection );
oTex = Tex;
}
float4 PixScene( float2 Tex : TEXCOORD0 ) : COLOR0
{
return tex2D( g_samScene, Tex );
}
Once I get my head around manipulation texture color I should be alright.
Thanks again Zman.
Pieter has some HLSL tutorials here which includes a basic diffuse
directional light http://www.pieterg.com/Tutorials.php
--
Zman (mailto:zm...@thezbuffer.com)
http://www.thezbuffer.com
News and Resources for Managed DirectX
"Moo Mansun" <urlo...@nothing.com> wrote in message
news:8bee39dd5ebb4bf7...@ureader.com...
The light vector is simple enough. How do I get the normal?
I found this code snippit, however, it does not support textures. I am
using tex2D in the pixel shader, so my question is how do I integrate this
into the return?
float4x4 matWorldViewProj;
float4x4 matWorld;
float4 vecLightDir;
struct VS_OUTPUT
{
float4 Pos : POSITION;
float3 Light : TEXCOORD0;
float3 Norm : TEXCOORD1;
};
VS_OUTPUT VS(float4 Pos : POSITION, float3 Normal : NORMAL)
{
VS_OUTPUT Out = (VS_OUTPUT)0;
Out.Pos = mul(Pos, matWorldViewProj); // transform Position
Out.Light = vecLightDir; // output light vector
Out.Norm = normalize(mul(Normal, matWorld)); // transform Normal
and normalize it
return Out;
}
float4 PS(float3 Light: TEXCOORD0, float3 Norm : TEXCOORD1) : COLOR
{
float4 diffuse = { 1.0f, 0.0f, 0.0f, 1.0f};
float4 ambient = {0.1, 0.0, 0.0, 1.0};
return ambient + diffuse * saturate(dot(Light, Norm));
}
Cheers Zman.
I have two questions:
1. How do you output a normal?
2. Is the float4 returned by tex2d() a rgba value?
3. What range should those values fall within?
Thanks Zman, I should be able to implement point lights after this.
To be honest, if you don't know what normals are you really are not going to
get very far into shaders. I would suggest getting some 3d throry books and
get the fundamentals down or go back to the fixed function pipeline for now.
--
Zman (mailto:zm...@thezbuffer.com)
http://www.thezbuffer.com
News and Resources for Managed DirectX
"Moo Mansun" <urlo...@nothing.com> wrote in message
news:53162d2f0de64d26...@ureader.com...
I assume you mean directional lights. Point lights is a whole other story.
--
Zman (mailto:zm...@thezbuffer.com)
http://www.thezbuffer.com
News and Resources for Managed DirectX
"Moo Mansun" <urlo...@nothing.com> wrote in message
news:099cce9d13c94edd...@ureader.com...
I have had a go at implementing that algorythm into the CustomUI sample. I
have just used a static vector for the Light.
Is the light vector static anyway, or is there computation required to
obtain that value?
I only ask because this implementation provides a 'natural' form of ambient
light and the texture look richer.
If the vector between the light source and the material had to be calculated,
would this change the outcome?
//--------------------------------------------------------------------------------------
// File: Directional_Light.fx
//
// A Directional Light HLSL file for the CustomUI sample.
// Implementing HW T&L.
//
// Copyright (c 2005) Moo Mansun. All rights reserved.
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
// Global variables
//--------------------------------------------------------------------------------------
float4x4 worldMatrix; // World matrix for object
float4x4 worldViewProjection; // World * View * Projection matrix
texture sceneTexture;
//Sampler state for texture lookup
sampler g_samScene =
sampler_state
{
Texture = <sceneTexture>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};
//Return variables for VertScene
struct VS_OUTPUT
{
float4 Pos : POSITION;
float3 Light : TEXCOORD2;
float3 Norm : TEXCOORD0;
float2 Tex : TEXCOORD1;
};
//Vertex Shader Routine
VS_OUTPUT VertScene( float4 Pos : POSITION, float2 Tex : TEXCOORD0, float3
Normal : Normal )
{
VS_OUTPUT Out = (VS_OUTPUT)0;
Out.Pos = mul( Pos, worldViewProjection );
Out.Light = (-0.78, -0.68, 0.16, 10.0); //output light vector
Out.Norm = normalize(mul(Normal, worldMatrix));
Out.Tex = Tex;
return Out;
}
//Pixel Shader Routine
float4 PixScene( float2 Tex : TEXCOORD1, float3 Light: TEXCOORD0, float3
Norm : TEXCOORD2 ) : COLOR
{
float4 tex = tex2D( g_samScene, Tex );
float4 ambient = (0.0, 0.0, 0.0, -0.02);
float4 diffuse = (1.0, 0.0, 0.0, 0.04);
return tex + ambient + diffuse * saturate(dot(Light, Norm));
}
//--------------------------------------------------------------------------------------
// Techniques
//--------------------------------------------------------------------------------------
technique RenderScene
{
pass P0
{
VertexShader = compile vs_1_1 VertScene();
PixelShader = compile ps_1_1 PixScene();
}
}
//Cheers Zman...
Sweet, directional light and perfect too.
I have one question:
The float4 structure,
float4 ambient = (0.0, 0.0, 0.0, -0.02);
What are each of the params, are the rgba?
Just replace CustomUI.fx with this code for directional light effect.
Next up, volume shadows...
//--------------------------------------------------------------------------------------
// File: Directional_Light.fx
//
// A Directional Light HLSL file for the CustomUI sample.
// Implementing HW T&L.
//
// Copyright (c 2005) Moo Mansun. All rights reserved.
// Big thanks to Zman.
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
// Global variables
//--------------------------------------------------------------------------------------
float4x4 worldMatrix; // World matrix for object
float4x4 worldViewProjection; // World * View * Projection matrix
texture sceneTexture;
//Sampler state for texture lookup
sampler g_samScene =
sampler_state
{
Texture = <sceneTexture>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};
//Return variables for VertScene
struct VS_OUTPUT
{
float4 Pos : POSITION;
float3 Light : TEXCOORD2;
float3 Norm : TEXCOORD1;
float2 Tex : TEXCOORD0;
};
//Vertex Shader Routine
VS_OUTPUT VertScene( float4 Pos : POSITION, float2 Tex : TEXCOORD0, float3
Normal : Normal )
{
VS_OUTPUT Out = (VS_OUTPUT)0;
Out.Pos = mul( Pos, worldViewProjection );
Out.Light = (1.0, 1.0, 1.0, 1.0); //output light vector
Out.Norm = normalize(mul(Normal, worldMatrix));
Out.Tex = Tex;
return Out;
}
//Pixel Shader Routine
float4 PixScene( float2 Tex : TEXCOORD0, float3 Light: TEXCOORD2, float3
Norm : TEXCOORD1 ) : COLOR
{
float4 tex = tex2D( g_samScene, Tex );
float4 ambient = (0.0, 0.0, 0.0, -0.02);
float4 diffuse = (1.0, 1.0, 1.0, 0.1);
GeForce FX 5200+ recommended.
//--------------------------------------------------------------------------------------
// File: Directional_Light.fx v1.0
//
// A Directional Light vertex shader HLSL file for the
// CustomUI sample.
// Implementing Real-Time Vertex Shading - HW T&L.
return Out;
}
//Updated equation
return (tex + ambient + diffuse) * saturate(dot(Light, Norm));
1. Make sure you normalize your light vector - yours in constant and happens
to be normalized, but when you paramterize it that won't always be the case.
2. dot(Light, Norm)) only varies per vertex so don't recalculate it in the
pixel shader. Do it in the vertex shader and let the hadware ineterpolate
3. You may need to saturate the final color as it could go over 1.0
4. You are varying the ambient light color by the directional light -
ambient is color only so never varies.
Basically you should calculate the vertex color in the vertex shader with
something like
dirLightAttn=saturate(dot(transformedNormal, normalize(LightDir)))
outCol=saturate(material * (ambient + dirLightAttn * LightCol))
then add in the texture color only in the pixel shader
outCol=saturate(inCol * tex2D(.....))
--
Zman (mailto:zm...@thezbuffer.com)
http://www.thezbuffer.com
News and Resources for Managed DirectX
"Moo Mansun" <urlo...@nothing.com> wrote in message
news:ad8b59d268d247a0...@ureader.com...
What's the additional value in the float4 for?
In a Vector3, it is xyz.
Thanks Zman.
Whilst it mimics a directional light, the source must be modified to account
for the difference in the position of the light relative to the material.
If not, the shading effect is permantly fixed from a single point.
(tex + ambient + diffuse) * saturate(dot(Light, Norm));
That line is varying the ambient light by a factor based on the normal and
the light angle which is not what ambient light does.
--
Zman (mailto:zm...@thezbuffer.com)
http://www.thezbuffer.com
News and Resources for Managed DirectX
"Moo Mansun" <urlo...@nothing.com> wrote in message
news:a565bfbe355c4742...@ureader.com...
I have run into a snag, I need to calculate the worldMatrix. Now, I know
this should be available as the inverse of the viewMatrix, how do I
calculate that?
Thanks Z
World != inverse(View). Not sure what you are trying to do here. Generally
there is no relation between the two.
Typically:
World is something you create to move objects from their default position
(usually around 0,0,0) to another place and orientation in the world. You
don't so much calculate it from anything as just create it. Ususually using
a product of Matrix.Translate, .Rotate and .Scale
View is also something you create - typically it represents the position of
the camera in the world and provides a transformation of the world into a
position and orientation from the point of view of that camera. Typically
you create this yourself using one of the LookAt functions, or get it from a
Camera object (for example in the DXframework classes).
--
Zman (mailto:zm...@thezbuffer.com)
http://www.thezbuffer.com
News and Resources for Managed DirectX
"Moo Mansun" <urlo...@nothing.com> wrote in message
news:a5ff957bde044a16...@ureader.com...
There is a relationship between viewMatrix and worldMatrix, the worldMatrix
is the inverse of the viewMatrix.
As for the code, the visual effect of that file is a projected shading of
the vertices from a fixed point. I have tested it.
Mw = Mwr * Mwt, where Mwr is the rotation part and Mwtb is the translation
part.
http://msdn.microsoft.com/archive/default.asp?
url=/archive/en-us/dnardir3d/html/d3dlight3.asp
> There is a relationship between viewMatrix and worldMatrix, the
> worldMatrix
> is the inverse of the viewMatrix.
No there is not. Apparently I am not the only one who disagrees with you -
you are being told the same thing on gamedev
http://www.gamedev.net/community/forums/topic.asp?topic_id=349940
http://www.gamedev.net/community/forums/topic.asp?topic_id=349970
and you choose not to believe it on there either.
> As for the code, the visual effect of that file is a projected shading of
> the vertices from a fixed point. I have tested it.
I'm sure it looks right, but the math is wrong doesn't matter how many times
you tell us you think it is right. People will read this thread, see your
example and assume its correct. Even worse, you put my name in it so I feel
a responsibility to correct it.
I'm not sure what reaction you expect to get by asking questions then
arguing with the correct answers as if you are the expert but generally its
not a way to find friends in forums and newsgroups. Good luck to you - end
of the thread for me.
--
Zman (mailto:zm...@thezbuffer.com)
http://www.thezbuffer.com
News and Resources for Managed DirectX
"Moo Mansun" <urlo...@nothing.com> wrote in message
news:13f31a574a4146ea...@ureader.com...
This is my problem:
Quote:
"Typically:
World is something you create to move objects from their default position
(usually around 0,0,0) to another place and orientation in the world. You
don't so much calculate it from anything as just create it. Ususually using
a product of Matrix.Translate, .Rotate and .Scale
View is also something you create - typically it represents the position of
the camera in the world and provides a transformation of the world into a
position and orientation from the point of view of that camera. Typically
you create this yourself using one of the LookAt functions, or get it from a
Camera object (for example in the DXframework classes)."
I have a viewMatrix that represents the camera, however, creating another
instance of the Matrix will have the effect of manipulating the current
matrix.
If I try to use Matrix.Translate, .Rotate and .Scale I will alter the output
to the screen. How do I get the worldView Matrix without doing this?
--
Zman (mailto:zm...@thezbuffer.com)
http://www.thezbuffer.com
News and Resources for Managed DirectX
"Moo Mansun" <urlo...@nothing.com> wrote in message
news:df8b9b6322c2439a...@ureader.com...