Visual Phong Shading

Started by
4 comments, last by Claudio 15 years ago
Hi. I'm using the GPU and the DirectX 9. The target is the implementation of the Phong Shading. The installed DirectX not support this Shading. Looking the link: http://www.nbb.cornell.edu/neurobio/land/OldStudentProjects/cs490-95to96/guo/report.html: 1-compute the normal of each vertex of triangular meshes of 3D object 2-compute the normal for each point of the mesh (through each horizzontal scan-line onto the 2D screen) on the base of the position (u, v) of the same pixel onto the screen. Here, is (u, v) centred in the middle of the screen ? 3-the normals, of the point 2, are applied to the Phong Model Reflection. Is right all This ? All this will be implemented in the Pre-Shader. In this way, I've to know the exactly position of each pixel of the virtual object onto the screen. Is right now ? There is an alternative and more simple solution ? Thanks.
Advertisement
Hi.

Is possible to implement the Phong Shading with Pre-Shader ?

And so, the problem is:
I've got the 3D position of all vertices and how can I implement the Phong Shading for all the pixel (of the virtual object) onto the screen ?

Someone know the solution to my problem ?

Thanks.

Hi,

Pre-Shaders are executed in software inside D3DX. So, it's so difficult to perform Phong Model Lighting and Shading with pre-shaders. You must have all vertex normals, world positions etc.

Why don't you try HLSL? It's so easy to get/use local-space positions of vertices and normals. With this, you can perform your own Phong Model Shading easily.

One more thing to say:
Pre-shaders are executued "per-vertex". Per-pixel shading gives better visual results.
There's no "hard", and "the impossible" takes just a little time.
Quote:Original post by programci_84
Pre-Shaders are executed in software inside D3DX. So, it's so difficult to perform Phong Model Lighting and Shading with pre-shaders. You must have all vertex normals, world positions etc.

Why don't you try HLSL? It's so easy to get/use local-space positions of vertices and normals. With this, you can perform your own Phong Model Shading easily.
The code will has to be directly executed into the GPU of the graphic card Nvidia and it has to be implemented in the file with extension FX.

In this case, my problem could be the calculus of the position of verteices (in pixel of the screen !!!) that is necessary for the linear interpolation of normals of mesh.

Thanks for the moment.

[Edited by - Claudio on April 21, 2009 7:46:07 AM]
Quote:Original post by programci_84

Why don't you try HLSL? It's so easy to get/use local-space positions of vertices and normals. With this, you can perform your own Phong Model Shading easily.

Yes with HLSL but I've to access to each pixel of the screen, after getting the position (in pixel ???) and normal of all the meshes.

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.

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.

This topic is closed to new replies.

Advertisement