Jump to content
  • Advertisement
Sign in to follow this  
Corefanatic

DX11 [DX11] Inferred Renderer - How to create the stipple pattern

This topic is 2597 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 all,

I am trying to implement a inferred renderer. I get how it works, but am stuck at the point where I write pixels into the g_buffers in stipple pattern.

So my idea is to use the stencil buffer to mark the pixels that can be written to in the g_buffer. This would mean I would fill the g_buffers with opaque objects data and mark each top-left pixel of each 4x4 pixel block in the stencil buffer, making it reserved.

Then render the transparent objects and overwrite the pixels in each 4x4 block with each transparent layer, marking the stencil buffer as I write each transparent layer.

However I am quiet puzzled by how to selectively mark the pixels with stencil, since I do not know the position of the pixel until pixelshader, and as far as I know there is not a way to write into stencil buffer from pixel shader.

I ma sure there must be an easy way to do this, does anyone have any experience with writing into stipple pattern?

Share this post


Link to post
Share on other sites
Advertisement
If there are no transparent objects covering an opaque surface, then you want it to write into every pixel in your [font="Courier New"]N[/font]x[font="Courier New"]N[/font] block structure, so opaque surfaces should not be stippled at all.

For transparent surfaces, you can find the screen-space position of the pixel (using SV_Position) and mod it with [font="Courier New"]N[/font] to find out which sub-pixel of your block is currently being drawn. If the sub-pixel location isn't allowed (as defined by the transparent object's 'layer' value), then you can use [font="Courier New"]clip[/font] to stop drawing.

Share this post


Link to post
Share on other sites

If there are no transparent objects covering an opaque surface, then you want it to write into every pixel in your [font="Courier New"]N[/font]x[font="Courier New"]N[/font] block structure, so opaque surfaces should not be stippled at all.

For transparent surfaces, you can find the screen-space position of the pixel (using SV_Position) and mod it with [font="Courier New"]N[/font] to find out which sub-pixel of your block is currently being drawn. If the sub-pixel location isn't allowed (as defined by the transparent object's 'layer' value), then you can use [font="Courier New"]clip[/font] to stop drawing.


Those parts I know and have figured out.

What I am trying to do is as follows:



After writing in opaque the 4x4 block looks like this:

O = opaque

O|O
O|O

Now when I start drawing transparent I want to do this (positions in 4x4 block are reffered to in row major fashion starting at 0):

if the pixel's position is at position 1 of the 4x4 block and the position is unused by any transparents, write into position 1, else clip
if it is not at position 1 and position 1 is unused clip

this goes for all three possible positions of transparent pixels


Now I need some place where I can read what positions are unused and used and if I transparent pixel I need to mark its position as used.

Basically I need a buffer with a single bit for each pixel which I can read and write to from pixel shader. I am thinking of something like read write structured buffer in DX11, but haven't really looked much into that.

Share this post


Link to post
Share on other sites
Now I need some place where I can read what positions are unused and used and if I transparent pixel I need to mark its position as used.
The basic inferred implementation is a lot simpler than that. Instead of inspecting the block to see which positions are used/unused, it simply associates different layers with different positions.
e.g. for a 2x2 block, layer 0 always only writes to upper-left pixels, layer 1 to upper-right pixels, layer 2 to lower-left pixels and layer 3 to lower-right pixels.

If two transparent objects from the same layer are rendered to the same block, then only the nearest one ends up written (due to the z-test).

Share this post


Link to post
Share on other sites

[quote name='Corefanatic' timestamp='1317698994' post='4868835']Now I need some place where I can read what positions are unused and used and if I transparent pixel I need to mark its position as used.
The basic inferred implementation is a lot simpler than that. Instead of inspecting the block to see which positions are used/unused, it simply associates different layers with different positions.
e.g. for a 2x2 block, layer 0 always only writes to upper-left pixels, layer 1 to upper-right pixels, layer 2 to lower-left pixels and layer 3 to lower-right pixels.

If two transparent objects from the same layer are rendered to the same block, then only the nearest one ends up written (due to the z-test).
[/quote]

Yeah, you are right, I guess I am overcomplicating things :D. I'll sort my transparents by depth and then render with alternating stipple pattern like MJP uses in his example on his blog. I will write here If I have nay further question. Thx for the help!

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!