Pages: [1]   Go Down
Author Topic: Vertex Shader - Culling  (Read 8974 times)
May 30, 2012, 09:03:42 pm
Can vertices be culled from within a vertex shader in such a way that they are discarded (not just clipped) from the rendering pipeline (thus providing a performance gain) ?

I am looking for a simple way to selectively stop vertices from being rendered
(i.e. a custom 'culling' method, but from within a shader).

I am aware that a vertex shader can only transform vertices and have a feeling that excludable vertices would have to be processed before they are sent to the shader.

So, unless there is a way to fool the pipeline I'm not sure how yet..

If vertices are in a shader they are 'already in the pipeline' and can't be discarded.
May 31, 2012, 06:08:25 pm
set out.hpos to 0
May 31, 2012, 06:46:33 pm
set out.hpos to 0

Assuming your hpos is equivalent to my pos:POSITION
I attempted the following yesterday, but it has no effect
(i.e. FPS does not increase, implying the vertices are being discarded):

struct VS_INPUT
   float4 position   : POSITION;

struct VS_OUTPUT
   float4 pos   : POSITION;

   VS_OUTPUT vsOut;

   float4x4 w = worldArray[IN.index];
   float4 wpos = mul(IN.position, w);

   vsOut.pos = 0;//mul(wpos, vp);
   return vsOut;

Everything I am reading suggests that the vertex will still be processed, even if it isn't visible.
Let me know how you'd expect hpos = 0 to be interpreted by the shader and the subsequent pipeline.
June 01, 2012, 08:35:01 am
I think it is done per vertex instead of per pixel like clip() command.

I expect the rasterizer still executes the vertex shader but empty fragments arrive at the pixel shader.
June 01, 2012, 08:36:33 am
As far as I know, you'd need a geometry shader to actually discard triangles/vertices.

The best you could do without that is to place them behind the camera like in the way of Tom or discard the pixels.
June 01, 2012, 11:01:07 am
Problem is that while a specific vertex might be behind the camera and could be culled, a triangle is made of three vertices, and can be visible even if just one vertex is visible. So the vertex shader by itself cannot know if the vertex is visible or not. Also even if you manage to do so, I doubt very much that this will have any influence on the performance, it might even lower the performance.
June 01, 2012, 11:20:45 am
Yes, that is very true. I think you simply have to accept that you can discard pixels, but can't discard triangles. (Unless you can use a geometry shader.)
June 01, 2012, 12:00:03 pm
No problem. 

I'll go to Plan-B and manage my instance/object data before they are passed to the shader.
June 01, 2012, 03:13:22 pm
That is by far the best solution!
Pages: [1]   Go Down
Jump to: