• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
NumberXaero

Lens flare position

4 posts in this topic

Im going to do lens flares but Im not sure how to handle culling the reference point. Although its a deferred renderer, more control over placement is wanted so doing it purely as a post effect on the bright parts probably isnt an option.

I need to have a set of flare quads (rects...) drawn at specific locations offset from the specified location in 3d, but I need the entire effect (the quad set) to pop on and off depending on the visibility of the flares 3d reference point.

 

In short, I need to draw or not draw the flare quad set based on whether a single 3d position is culled or not so it pops around occluder edges..... What would be a good way to do that?

 

I read one way, where the effect was drawn whether or not the results of a single pixel depth read back was visible or not (ugh, depth read)

Ive seen occlusion queries suggested, but seems like over kill.

I was thinking maybe shooting a ray from the 3d flare position to the near plane through the scene and seeing if any triangles are hit (but then theres the triangle picking overhead.....)

Point sprites, although I read they cull by the center (which is good in this case), it seems some hardware might not do this, and if it did, only the first flare quad would cull but the others that belong to it would escape around the occluder.

 

So Im not really sure what to do.

 

 

 

0

Share this post


Link to post
Share on other sites

nowadays the best way is probably to read the depth position in the vertex shader, depending on the occlusion result, you get transform the vertex properly or set some default value, e.g. (0,0) as position and all flares gonna be culled.

 

that's minimal latency (occlusion queries are probably just available at least one frame later), minimal cost (it's not some per pixel cost, but just few e.g. 4 vertex read per flare) and low implementation time (just set the depth sampler, z-texture and the proper 2d read position to the lens flare shader).

2

Share this post


Link to post
Share on other sites


I read one way, where the effect was drawn whether or not the results of a single pixel depth read back was visible or not (ugh, depth read)
I've used these technique, and a "soft" variation.

What's wrong with doing depth reads? The lens flares don't need to do depth-testing or depth-writes, so there's no conflict there. Which API are you using?

 

For the soft variation, I read a 16x16 pixel area around the centre of the light-source, testing for depth values that are closer than the light source.

For each light-source, I draw a 16x16 pixel quad to an intermediate render-target, and the "depth test" shader outputs black or white, depending on whether that pixel is occluded or not.

I then down-sample this intermediate texture 16x, so that I end up with one pixel per light-source, with a fractional occlusion factor (16x16 booleans averaged == 256 possible values).

If I know there's 16 lights that need a fractional occlusion value in the scene, then I'll make my intermediate render target 256x16 pixels (i.e. that's 16 squares, of 16x16 pixels).

 

The lens flare shader can then sample one value from the downsampled intermediate texture, and get a fractional occlusion value from 0.0f to 1.0f (in 1/256 increments).

 

Here's a visual example with the scene above, and the intermediate texture below. On the right, the sun's lens flare is still drawn, but with 50% of the regular alpha.

YXKtIZX.png

 

For smaller light-sources (like the individual lights on the stadium spotlight arrays in that picture), I use the method you mention, where the lens-flare itself samples the depth-buffer once, and hides itself if this manual/custom depth-test fails.

2

Share this post


Link to post
Share on other sites

Sorry, should have expanded, it wasnt a depth read in the shader, the example I was referring to was a single pixel depth read on the cpu (glReadPixels).

Pretty good ideas, so do you just use the fractional occlusion value of 0.0 to essentially cull the lights flare effect by completely blending it out?

How does the testing work for manual/custom depth test? I guess Im kinda sketchy on how I would render the individual flare quads based on a single depth
value thats based on a center point of a quad over the lights 3d point in the screen.
With the 16x16 downsample suggestion assuming you just blend out completely using a occlusion value of 0.0, it makes sense, using 0.0 kills all the flare
quads you had planned all at the same time.

How are you determining the center of the 16x16 area? Manually projecting the light point?
Without using the 16x16 blend method mentioned, or single depth read on cpu compared against the manually projected depth, how would you go about killing
the multiple flare quads based on the depth test result of the main flare point?

Im using opengl.

0

Share this post


Link to post
Share on other sites

You might be able to find a tutorial by searching for "opengl use depth buffer as texture" etc. Being able to use the depth-buffer as a texture is an important ability for shadow-mapping, deferred rendering, etc, so there should be some guides around.
My OpenGL is a bit rusty, but IIRC the process of reading the depth buffer in a shader requires the use of FBO's... You bind a depth-texture to an FBO as the depth/stencil target, you draw your scene, and then afterwards, you can use that depth-texture as if it were a regular old texture. You can then sample from it in a fragment shader, just like you do with any other texture.

the example I was referring to was a single pixel depth read on the cpu (glReadPixels).

Yeah, ok that would be bad biggrin.png

How are you determining the center of the 16x16 area? Manually projecting the light point?
Without using the 16x16 blend method mentioned, or single depth read on cpu compared against the manually projected depth, how would you go about killing
the multiple flare quads based on the depth test result of the main flare point?

Yeah, on the CPU side, you project the light source into screen coordinates. If done correctly, this gives you the x/y position, but also the z value (all these values from -1 to 1 in range). To convert the x/y values to texture coordinates, you can rescale them to the 0-1 range (and maybe flip y upside down if GL's texture coordinates require that).
 
In the single depth sample method, in your pixel shader, you can sample the depth texture at this x/y position, and discard (or output alpha of zero) if the returned depth value is less than the z value calculated on the CPU.
 
In the 16x16 method, in your first (intermediate) pixel shader, you sample the depth texture at this x/y position, plus an offset depending on which pixel is being drawn. Then if the returned depth value is less than the z value calculated on the CPU you output black, otherwise output white. Then you calculate mip-maps for this intermediate texture.
Then in the second (actual lens flare) pixel shader, you sample the lowest-resolution mip-map of the intermediate texture, and use the returned value to scale your alpha value (or discard if the sampled value is zero).

 

If you're using a modernish GPU (e.g. GL3+) then you can do these texture fetches in the vertex-shader instead of for every single pixel in the lens flare.

1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0