light

Started by
3 comments, last by Claudio 15 years, 6 months ago
Hi. My code is:
//---PARAMETERS
//------------------------------>
row_major float4x4 world : WORLD;
row_major float4x4 view : VIEW;
row_major float4x4 proj : PROJECTION;

float4 baseColor : DIFFUSECOLOR = float4(0.8f,0.8f,0.8,0.7);


//---SHADERS
//------------------------------------------------------->
void PerPixelVS(	in Vertex vertex,out FragmentA fragment,
						uniform float4x4 world,uniform float4x4 view,uniform float4x4 proj)
{
//	Compute WORLDVIEWPROJECTION matrix (preshader)	
	float4x4 worldViewProj = mul(world,mul(view,proj));
	float4x4 worldView = mul(world,view);
	
//	Compute Screen Space Position	
	fragment.position = mul(float4(vertex.position,1),worldViewProj);

//	Pass view coordinate normal to pixel shader for lighting [vertex.normal * Transpose(Inverse(worldView));
	fragment.normal_VC = mul(float4(vertex.normal,0),worldView);
}
void PerPixelPS(in FragmentA fragment,out Pixel pixel)
{
	pixel.color.xyz = baseColor.xyz * dot(normalize(fragment.normal_VC), float3(0,0.5,-1));	//ps_1_1: error! texcoord are restricted to [0,1]
	pixel.color.w = baseColor.w;
}

void PerVertexVS(	in Vertex vertex,out FragmentB fragment,
						uniform float4x4 world,uniform float4x4 view,uniform float4x4 proj)//utilizzati su majorana
{
//	Compute WORLDVIEWPROJECTION matrix (preshader)	
	float4x4 worldViewProj = mul(world,mul(view,proj));
	float4x4 worldView = mul(world,view);
	
//	Compute Screen Space Position	
	fragment.position = mul(float4(vertex.position,1),worldViewProj);

//	Compute color
	fragment.color.xyz = baseColor.xyz * dot(mul(float4(vertex.normal,0),worldView),float3(0,0.5,-1));
										 //dot(vertex.normal,float3(0,1,0) );
	fragment.color.w = baseColor.w;
}
void PerVertexPS(in FragmentB fragment,out Pixel pixel)
{
	pixel.color = fragment.color;
}//*/









The light is diffuse and the type of light is point looking the equation:
fragment.color.xyz = baseColor.xyz * dot(mul(float4(vertex.normal,0),worldView),float3(0,0.5,-1));





In the vertex e pixel Shader implement the lightning diffuse looking
DIFFUSECOLOR




I use the DirectX 9 and the gouraud shading. My question is: - the equation:
pixel.color.xyz = baseColor.xyz * dot(normalize(fragment.normal_VC), float3(0,0.5,-1));




implementing in the pixel and vertex shaders is the equation of the diffuse lightning and point light ??? and not of the Gouraud Shading i suppose; - in the same equation, i can write it as:
color_vertex*dot(Normal_vertex,Ldir)




???, where "dot(a,b)" is the scalar product of vector "a" and "b", while "Ldir" is the direction from the vertex to the source of light and vertex.normal is the struct "vertex" that contain the normal in the camp of "normal" (so "vertex.normal"). Obviusly, "vertex.normal" is normalized at unitare module (module=1) and "mul" is the vectorial product. Where "Ldir=float3(0,0.5,-1)" and "color_verte=baseColor.xyz". These are my question. [Edited by - Claudio on October 16, 2008 3:06:11 AM]
Advertisement
What is your question?
Quote:Original post by BosskIn Soviet Russia, you STFU WITH THOSE LAME JOKES!
Quote:Original post by Claudio
implementing in the pixel and vertex shaders is the equation of the diffuse lightning and poit light ??? and not of the Gouraud Shading i suppose;
I'm not sure I follow. Bare in mind that shading and lighting are actually different things - the common mistake is Phong shading (interpolating inputs) and Phong lighting (an equation found by Phong Bui-Tuong in 1973 iirc). Gouraud shading is just a case of interpolating the output of lighting linearly across the surface - what happens if you evaluate lights in the vertex shader. Phong shading is what happens for per-pixel lighting.

Quote:Original post by Claudio
- in the same equation, i can write it as: *** Source Snippet Removed *** ???, where "dot(a,b)" is the scalar product of vector "a" and "b", while "Ldir" is the direction from the vertex to the source of light and vertex.normal is the struct "vertex" that contain the normal in the camp of "normal" (so "vertex.normal"). Obviusly, "vertex.normal" is normalized at unitare module (module=1).
If I follow you correctly then, yes you can interchange these two fragments. You need to be very sure that vectors/points are in the same space (e.g. both in world space or both in view space) and the direction of vectors is correct (confusing vertex-to-light and light-to-vertex is very easy). Anything else is likely to just be a syntax change...


hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Quote:Original post by jollyjeffers
Quote:Original post by Claudio
implementing in the pixel and vertex shaders is the equation of the diffuse lightning and poit light ??? and not of the Gouraud Shading i suppose;
I'm not sure I follow. Bare in mind that shading and lighting are actually different things - the common mistake is Phong shading (interpolating inputs) and Phong lighting (an equation found by Phong Bui-Tuong in 1973 iirc). Gouraud shading is just a case of interpolating the output of lighting linearly across the surface - what happens if you evaluate lights in the vertex shader. Phong shading is what happens for per-pixel lighting.

Quote:Original post by Claudio
- in the same equation, i can write it as: *** Source Snippet Removed *** ???, where "dot(a,b)" is the scalar product of vector "a" and "b", while "Ldir" is the direction from the vertex to the source of light and vertex.normal is the struct "vertex" that contain the normal in the camp of "normal" (so "vertex.normal"). Obviusly, "vertex.normal" is normalized at unitare module (module=1).
If I follow you correctly then, yes you can interchange these two fragments. You need to be very sure that vectors/points are in the same space (e.g. both in world space or both in view space) and the direction of vectors is correct (confusing vertex-to-light and light-to-vertex is very easy). Anything else is likely to just be a syntax change...


hth
Jack


So, if I have understand correctly:
- the equations are the light diffuse and point-type, and not Gouraud Shading;
- the vertex normal is in the camera system (
http://msdn.microsoft.com/en-us/library/bb172390(VS.85).aspx).

Is correct what I've write now ???

Have I interpretated correctly the code (that I've show in the original message) ??? about your opinion.

[Edited by - Claudio on October 14, 2008 4:01:44 AM]
I've understand that is diffuse illumination looking http://www.gamasutra.com/features/20030418/engel_02.shtml.

but remaining the same initial problem that I've write in the intial message and the question on "Ldir" is also open, where "Ldir" I think is the direction of light.

This topic is closed to new replies.

Advertisement