Jump to content
  • Advertisement
Sign in to follow this  
dhanji

Occluded normal pixel-clipping

This topic is 5407 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 kinda had this idea about clipping the back-side of objects so the pixel shader doesnt have to draw occluded pixels. If you take the dot(normal, EyeToVertexNormal) and pass that value to clip(), it discards pixels whose normals are facing away from the camera. My question is, do u think the speed increase of clipping those pixels would be worth it for the additional steps in the vertex shader (to calculate the clipping term)? And is this kinda overkill? Also is there a case where such normals may need to be visible? thanks!

Share this post


Link to post
Share on other sites
Advertisement
The hardware will very efficiently detect back-facing triangles and bypass all pixel shading on them. Don't worry about this -- your pixel shader code won't even be invoked for back-facing triangles.

EDIT: Assuming you're not using D3DCULL_NONE, of course. [smile]

Share this post


Link to post
Share on other sites
Quote:
The hardware will very efficiently detect back-facing triangles and bypass all pixel shading on them. Don't worry about this -- your pixel shader code won't even be invoked for back-facing triangles.


I am not talking about back-face culling. I am talking about culling occluded pixels that are on the "back" of the mesh from a viewer's perspective.

Share this post


Link to post
Share on other sites
Quote:
Original post by dhanji
I am not talking about back-face culling. I am talking about culling occluded pixels that are on the "back" of the mesh from a viewer's perspective.

Pixels that are on the "back" from the viewer's perspective exist on back-faces. They're culled.

You earlier said:
Quote:
If you take the dot(normal, EyeToVertexNormal) and pass that value to clip(), it discards pixels whose normals are facing away from the camera.

That's a backface: Normal facing away from the camera.

Share this post


Link to post
Share on other sites
I thought a backface is a normal opposite to the defined normal, i.e. the "back of the face". if u use CCW culling it culls all the backfaces of triangles formed by reading vertices counter-clockwise to generate faces. How is this the same as the back of the model?
If u use cull-none u see back and front faces textured (if I get inside a textured sphere I can see the textures no matter where the normals are facing), with CCW depending on ur vertex stream it will either make the inside visible or the outside. CW the opposite. What I mean is being able to see the exterior sphere surface (using a valid cullmode) so that when ur inside it u see nothing. But clipping the pixels that are on the exterior surface but occluded by the convex surface facing you:


E 0
[code

if E is eye, I mean clipping the right half of 0. as opposed to backface culling (which I take to mean) culling either the outer or inner surface of 0

Did I make a mistake? I am a bit confused...

Share this post


Link to post
Share on other sites
bump.

I don't have time to reply now, so I'm bumping this in the hope one would answer your post. Basically, you're kinda confused regarding what backface culling is (In the E 0 scene, back-face culling will cull away the right half of the '0'). But it happens [smile]

Will try to get back to you later, god-willing.

Share this post


Link to post
Share on other sites
from the directx sdk docs:

Quote:

Each face in a mesh has a perpendicular normal vector. The vector's direction is determined by the order in which the vertices are defined and by whether the coordinate system is right- or left-handed. The face normal points away from the front side of the face. In Microsoft® Direct3D®, only the front of a face is visible. A front face is one in which vertices are defined in clockwise order.


<THERE IS A PICTURE HERE OF A FACE WITH THE NORMAL ON IT>

Any face that is not a front face is a back face. Direct3D does not always render back faces; therefore, back faces are said to be culled. You can change the culling mode to render back faces if you want. See Culling State for more information.


According to this, as I understand it anyway, a back face is any face that (is not a front face) doesnt have a normal in its direction. This says nothing about the eye point or the camera.
From the tests that Ive done in the scene E 0
the inner surface of 0 is culled in a CCW cullmode. and if I switch the state to CW culling (reverse the triangle order) the outer surface becomes invisible. This does not act on the "back" of the model.
am I still on the wrong track?

Share this post


Link to post
Share on other sites
Quote:
According to this, as I understand it anyway, a back face is any face that (is not a front face) doesnt have a normal in its direction. This says nothing about the eye point or the camera.

The relation to the camera is implicit. Let's look closely at this statement:

Quote:
In Microsoft® Direct3D®, only the front of a face is visible. A front face is one in which vertices are defined in clockwise order.

We may ask here, defined in clockwise order relative to what?
Meaning, in which space?
Object space, world space, or camera space?

If you think about it, it's camera space. You're the camera, you're looking at a triangle. Are its vertices defined in clockwise order, relative to you? (anyone on the other side of the triangle will see that the vertices are defined in counter-clockwise order).

Let's say the vertices are ordered like this in the vertex buffer: 1, 2 and 3. And when we looked at them, from our current position, we saw this:

1
/ \
/ \
/ \
3-------2


Obviously, they're defined in a clockwise order to us. What does that mean?
D3D uses a left-handed system. If you do a cross product between any two edges, say 31 x 12 (or 12 x 23 or 23 x 31), according to the left-hand rule, the normal (the result of the cross product) points outside the page, towards us. That means, the triangle is facing us – it's a front-face.

What would someone on the other side see?

1

/ \
/ \
/ \
2-------3


To him, the vertices are defined in counter-clockwise order. What does that mean? The cross product of 12 x 23 (or 23 x 31 or 31 x 12), according to the left-hand rule, results in a normal that goes into the page, away from the viewer. That means, the triangle is facing away from us – it's a backface, and it's culled.

So, when you're using a left-handed system, you usually set culling to cull CCW triangles. With right-handed systems you usually cull CW triangles.

Quote:
From the tests that Ive done in the scene E 0
the inner surface of 0 is culled in a CCW cullmode.

Well, the eye-point is outside the sphere. Looking at the sphere, the left-part of it will contain faces that all look to the eye as if defined "clockwise", so they're not culled. However, the right half contains triangles that all look defined counter-clockwise, so they're culled.

If you're inside the sphere, everything will be culled, because everything will appear defined counter-clockwise.

Quote:
and if I switch the state to CW culling (reverse the triangle order) the outer surface becomes invisible.

If you're outside the sphere, the left-part would be defined in clockwise order and culled. The right-part won't be.

If you're inside, everything will be defined counter-clockwise, and thus not culled.

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!