Jump to content
  • Advertisement
Sign in to follow this  
Jacob Roman

Phong Shading And Gouraud Shading Not Working

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

Using DirectX8, I have this in my game loop to activate it: D3DDevice.SetRenderState D3DRS_SHADEMODE, D3DSHADE_PHONG and I'm using a point light, which is near a mesh that is not texturemapped. How come it still looks like it's flat shaded? Am I missing something?

Share this post


Link to post
Share on other sites
Advertisement
You mean to tell me that DirectX can't do it for me, and I have to manually pull it off? Why do they even have the renderstate if it's not even used?

Share this post


Link to post
Share on other sites
1) For D3DRS_SHADEMODE=D3DSHADE_PHONG to work, your graphics card must support that shade mode.

You can check whether yours does by looking at the "Microsoft.DirectX.Direct3D.ShadeCaps" device capability (D3DCAPS9.ShadeCaps).

Unfortunately, no consumer Direct3D graphics cards actually do expose that capability; so although the D3D API has support for it, D3DSHADE_PHONG is useless since no hardware has support for it (I don't even think the RefRast chooses to support that one).


2) If you actually want Phong shading, the best thing is to roll your own using shaders - put the vertex normals into a 3D texture coordinate or vertex colour or normal map, then perform your lighting computations per-pixel.


3) Gouraud shading on the other hand is supported on all modern graphics cards.

a. if your geometry looks faceted and each polygon doesn't appear to have any variation in light, I'd first suspect your vertex normals, how they're being computed, and how you're sharing them between vertices. I'd also have a sniff around the layout of your vertices (particularly if using FFP - remember: position, then normal, then colours, then UVs - no other order).

b. if your geometry all looks the same shade, I'd question the setup of your lights, materials, and lighting in general. Any attenuation and falloff settings would pique my interest there too.

c. if your geometry is very low polygon, and/or has large flat areas (e.g. like a wall or floor made from 2 polygons), then I'd say you should also consider the tesselation of your meshes - a point light on a 2-triangle wall isn't going to look like very much apart from a slight tint at the vertex closest to the light.


4) Small aside: The fixed function D3D lighting model is "Phong Illumination" - as in the equation used; some people mistake this for (and expect) "Phong Shading" - which requires per-pixel interpolation of the normal and per-pixel computation of the Phong Illumination equation.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
It's unfortunately quite simple:

D3DSHADEMODE enumeration indicates that D3DSHADE_PHONG is "Not supported".

If you want to really want to use phone shading, then implement it yourself as a pixel shader. I covered the regular Blinn-Phong BRDF in my journal.

hth
Jack

Share this post


Link to post
Share on other sites
Pah! Forums playing silly buggers. previous AP post was me [smile]

The journal entry I mentioned was here. By all means have a general browse of my journal as I've just finished covering the 5th of 5 BRDF's [smile]

Failing that, Simon knows more than most people do - you'd be well advised to pay attention to every word he typed [grin]

Cheers,
Jack

Share this post


Link to post
Share on other sites
Quote:
Original post by Jacob Roman
I have the Gouraud renderstate activated now, but it still looks flat shaded:


If the Gouraud is definately being enabled as expected, then from the screenshot, your normals look to be pointing in roughly the correct direction because you get variation of lighting and consistent lighting.

But it also looks like the all of the 4 normals for each quadrilateral/patch in your teapot meshes is pointing in the same same direction.

The normal for a vertex should be the average of the face normals of all faces connected to that vertex (whether physically through indexed primitives or just in the same position in space). The fact you're seeing faceted quads rather than faceted triangles makes me suspect the way your normals are being generated (or the data source they're from) even more.

A lesser possibility is your normals not being normalised, but it doesn't look like that from your screenshot. BTW: the lid on the teapot looks to be correctly shaded - even more suspicion about the normals of the pot itself.


An aside: http://www.sjbaker.org/teapot/

Share this post


Link to post
Share on other sites
Nevermind, it seems that Gouraud shading and Phong shading seems to work just fine on meshes from .X files. But on .RAW files such as my teapot, I get the flat shaded look. It may have something to do with calculating my normals I think like you said.

Share this post


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

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!