• Advertisement
Sign in to follow this  

Does anyone implemented the Gouraud shading algorithm in C# Directx ?

This topic is 1353 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

Hi, i am strucked in Lighting.. i need to implement the Gouraud's Shading algorithm in my project but i am beginner in directx so i didnt have any idea about how to implement ..! can anyone suggest some option for me..!!! i am currently working with directx9 in C#.

 

Share this post


Link to post
Share on other sites
Advertisement

Gouraud shading is pretty basic ... it is the default lighting model for D3D9 as far as I know. So, you'll just calculate the lighting values per vertex (using what ever lighting model desired such as blinn-phong) and then output the interpolated lighting value for each pixel (instead of recalculating the light for each pixel). 

 

Cheers!

Share this post


Link to post
Share on other sites

but i am so much confused and not having much knowledge about it my question seems to be silly so please bare with me,,how we can give the ambient,specular,diffuse color for each pixels in our object?, in other word how can we calculate the color value for per vertex?

Share this post


Link to post
Share on other sites

Well you should maybe give a bit more information : what have you tried - what doesn't work. Have you looked into any examples? In the DXSDK there is plenty of simple examples how to draw a triangle, how to light a triangle etc. 

 

Since you are using DX9, you may even start without using any shaders - the fixed function pipeline does all that you need for drawing gouraud shaded objects with ambient, diffuse and specular lighting. No need even for a lighting model or anything.

 

Typically to attain that objective you'll need (assuming that you are using fixed function pipeline) :

 

- vertex buffer (+index buffer) containing a 3d mesh with at least position and normal data

- vertex format declaration or FVF which matches the vertex buffer data

- a material description with desired ambient, diffuse, specular values

- a light structure with required lighting information (position, diffuse, direction)

- a view matrix describing your camera location and orientation

- a projection matrix to describe your view port form and znear and zfar planes

- a world matrix for the object orientation and location

- well of course a back buffer and z-buffer a required too ... and a window 

 

 

Anyway, take a look in to the examples of the DXSDK or google. You'll find source which does more and less exactly what you need.

 

Cheers!

 

[edit] when using the fixed function pipeline, you'll have less control over the lighting calculations. You'll need to use a vertex shader and a pixel shader to implement some specific lighting formulas. Once again, there are samples using VS/PS so it is pointless to write an exact answer for your question.

Edited by kauna

Share this post


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

  • Advertisement