Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>"There's more than one way to skin a cat" ;)</h2> <p><strong>Disclaimer:</strong> I never tried any of this, and not even sure if it works or even implementable. Just ideas, food for thought. </p> <p><sub>BTW, I'm still curious why would you need this ;)</sub></p> <ol> <li><p>Probably, you can emulate back-face culling yourself, before real hardware clipping</p> <ul> <li>Run your vertex and tessellation shaders as usual</li> <li>Transform and walk through your triangles in geometry shader (or in vertex shader, with tricks)</li> <li>Calculate dot product between camera's view direction and triangle's plane normal</li> <li>If (dot > 0): append triangle to output, if (dot &lt; 0): do not append (cull)</li> <li>You can read stream output data if you need it on CPU side</li> <li>You can somehow add <code>SV_PrimitiveID</code> to output if you need to know which primitives exactly was passed and which was clipped</li> <li>Then you can proceed with rendering in second pass. Your geometry already transformed, so no need for pre-rasterization stages. </li> <li>If your target hardware supports multiple streams (Shader Model 5.0), you can output one stream to buffer (to read on CPU) and rasterize second one. So all stuff dove in single pass.</li> </ul></li> <li><p>With your approach of output id from pixel shader:</p> <ul> <li>If you access output buffer on CPU side, you can sort it, iterate through it, remove or just ignore duplicates. <code>std::vector</code> + <code>&lt;algorithm&gt;</code> will do the trick.</li> <li>If you want to continue on GPU, you can do some sort of same thing in shader (pixel or compute), but this can be inefficient</li> <li>I think, you can use integer textures instead of structured buffers, if you want compatibility with Shader Model 4.</li> <li>More than one primitive can map to single pixel. So, you will not get indices of invisible primitives, those whose pixels was rejected on depth test (if primitive is completely overlapped with another). Depending on your needs this can be significant. Probably, you can disable depth testing and figure out how to write different</li> </ul></li> <li><p>With bool array approach, you, probably, cannot use <code>AppendStructuredBuffer</code>, but if you know primitive count before rendering, you can use <code>StructuredBuffer</code>, initialize it with zeros and simply write to it instead of appending.</p></li> <li><p>And of course, any time you can do it purely on CPU side. But that's not so funny.</p></li> <li><p><strong>Added due to comment</strong>. Wow, when you said "drawing something on each polygon face", a <a href="http://developer.download.nvidia.com/SDK/10/direct3d/samples.html" rel="nofollow">SolidWireframe sample</a> from Nvidia DirectX 10 SDK instantly popped up in my mind. It is an ideal usage for geometry shader. Basically:</p> <ul> <li>in GS you can provide each vertex with texcoords, depending on which face it belongs to</li> <li>hardware back-face culling will happen during rasterization</li> <li>in PS you sample your face texture with those texcoords</li> <li>as alternative, you can <em>probably</em> do texcoords in vertex shader. You could trick with instancing and <code>SV_VertexID</code>, <code>SV_InstanceID</code>: each first vertex id, each second vertex id, each third vertex id. It will cause branching, but will work even on SM 3.0 hardware, hopefully.</li> <li>corner case : you can precalculate alternative texcoord set for vertices offline. Hope, some 3D editors, such as 3dsMax supports it. So, no need to mess on runtime at all.</li> </ul></li> </ol> <p>Hope it helps. Please leave comment if it will =)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload