<\/a>A few minutes ago, I finally succeeded at getting stencil buffers to work in the VectorStorm engine.\u00a0 (I’ll be pushing this, along with a few related changes, into the public repository later today)<\/p>\nIgnoring the modified GUI which is visible here (which I’ll talk about more in a day or two), the important point to note is the box in the top right corner;\u00a0 that’s going to contain a minimap.<\/p>\n
The red area visible in it is actually just a small part of a very large red square which I’m drawing into the minimap.\u00a0 Stencil buffers are the way that I’m going to be constraining the minimap contents into that slightly oddly-shaped minimap area, rather than letting them extend out and overlap on top of everything else in the screen.<\/p>\n
Conceptually, stencil buffers are a bit like regular render buffers, except that instead of storing a color for each pixel, they store a simple number value.\u00a0 In the old days, that number value could be either 0 or 1.\u00a0 Nowadays, though, they can typically go as high as 255.\u00a0 I’m not using those at the moment, though;\u00a0 just 0 or 1 for me.\u00a0 Anyhow, at the start of the frame, the whole screen’s stencil buffer value is cleared to zero, and then when we render things, those things can change the value in the stencil buffer wherever they draw.\u00a0 Later, we can use the contents of the stencil buffer to constrain which pixels other things can get rendered to.\u00a0 Stencil buffers used to be most commonly used to implement mirrors and shadows, back in the PS2-era.\u00a0 There are better, faster ways to get those effects on modern hardware.\u00a0 But stencil buffers occasionally still come in handy.\u00a0 Especially in this sort of “irregularly shaped GUI windows” situation.<\/p>\n
In the VectorStorm implementation, I’ve exposed it this way:<\/p>\n
Any vsRenderTarget may be told to contain a stencil buffer (set the ‘stencil’ variable on the Settings object you use to construct the vsRenderTarget).\u00a0 That stencil buffer is then automatically cleared to a value of 0 at the start of each frame.\u00a0 Materials also now have an optional “stencil” field, which sets how things rendered with that material will affect the stencil buffer of the render targets they’re rendered into.\u00a0 In the screenshot here, I have the minimap window set to render a value of ‘1’ into the stencil buffer everywhere where it draws to the screen.\u00a0 Finally, there are new vsDisplayList commands to turn on and off testing against the stencil buffer.\u00a0 For convenience, you can set vsScenes as being subject to the stencil buffer, so everything in that vsScene is automatically constrained inside what has been rendered to the stencil buffer.\u00a0 So inside such a constrained vsScene, I’m rendering a huge red square, but because of the stencil buffer, it’s only actually showing up where it intersects with the minimap window.<\/p>\n
Next time, I’ll actually talk about this GUI.\u00a0 :)<\/p>\n","protected":false},"excerpt":{"rendered":"
A few minutes ago, I finally succeeded at getting stencil buffers to work in the VectorStorm engine.\u00a0 (I’ll be pushing this, along with a few related changes, into the public repository later today) Ignoring the modified GUI which is visible here (which I’ll talk about more in a day or two), the important point to…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[4,3],"tags":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/so9WK-stencils","_links":{"self":[{"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/posts\/2622"}],"collection":[{"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/comments?post=2622"}],"version-history":[{"count":0,"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/posts\/2622\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/media?parent=2622"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/categories?post=2622"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/tags?post=2622"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}