Jump to content
  • Advertisement
Sign in to follow this  
Claudio

Phong Shading

This topic is 3500 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The follow Pre-Shading are executed in the GPU of the graphic card and are implemented in the file with extension FX. They are without Phong Shading. The code for the Technique of Pre-Pixel Shader is:
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);
	
	 NormVectorLightDirection = -normalize(mul(float4(VectorLightDirection, 0), worldView));
}
void PerPixelPS(in FragmentA fragment,out Pixel pixel)
{
	pixel.color.xyz = baseColor.xyz * saturate(DiffuseIntensity * dot(normalize(fragment.normal_VC), NormVectorLightDirection));	//ps_1_1: error! texcoord are restricted to [0,1]
	pixel.color.w = baseColor.w;
}




while for the Pre-Vertex Shader:
 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
	NormVectorLightDirection = -normalize(mul(float4(VectorLightDirection, 0), worldView));

	fragment.color.xyz = baseColor.xyz * saturate(DiffuseIntensity * dot(normalize(mul(float4(vertex.normal,0),worldView)), NormVectorLightDirection));
	fragment.color.w = baseColor.w;
}
void PerVertexPS(in FragmentB fragment,out Pixel pixel)
{
	pixel.color = fragment.color;
}//




So, the Pre-Shader are: 1 - perPixel (Pre-Pixel Shader): VertexShader = compile vs_1_1 PerPixelVS(world,view,proj); PixelShader = compile ps_2_0 PerPixelPS(); 2 - perVertex (Pre-Vertex Shader): VertexShader = compile vs_1_1 PerVertexVS(world,view,proj); PixelShader = compile ps_1_1 PerVertexPS(); 3 - vertexOnly VertexShader = compile vs_1_1 PerVertexVS(world,view,proj); PixelShader = null; Now, my target is the implementation of the Phong Shading for the visual rendering (in HLSL). My question is: how can I make the computation pixel-per-pixel when the calculus is for each vertex, as will be more clearly looking the above code of the Pre-Shader.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!