Jump to content
  • Advertisement

Recommended Posts

I managed convert opengl code on http://john-chapman-graphics.blogspot.co.uk/2013/02/pseudo-lens-flare.html to hlsl, but unfortunately I don't know how to add it to my atmospheric scattering code (Sky - first image). Can anyone help me?

I tried to bind the sky texture as SRV and implement lens flare code in pixel shader, I don't know how to separate them (second image)



Edited by isu diss

Share this post

Link to post
Share on other sites

You don't add this into atmospheric scattering code, what you need is to have another render-pass. Take a look at my quick example on ShaderToy:


Atmospheric scattering is calculated in 1st buffer (e.g. as render-to-texture).

Then in 2nd buffer I scale & blur it (ideally you would want this to be done in separate steps -> downscale, horizontal blur, vertical blur, upscale)

Then in image (backbuffer) I calculate lens flare and overlay it over original image.


I used some magic constants to make it look a bit better.

Share this post

Link to post
Share on other sites

I looked at your opengl implementation. It's nice, that's what I want. But I've got some concerns over DX implementation. Do I need to draw a separate quad? What should I do to the sky dome? How do I bind backbuffer as SRV?

Share this post

Link to post
Share on other sites

What you need to do is:

  • Create two render targets - creating a render target explained here - https://www.braynzarsoft.net/viewtutorial/q16390-35-render-to-texture or http://www.rastertek.com/dx11tut22.html or even http://www.rastertek.com/dx11tut36.html (which also renders fullscreen quad)
  • In the first render target you will render your atmospheric scattering (e.g. the skydome with atmospheric scattering shader bound) - this will end up in a texture bound to render target - this is what Buf A is doing in ShaderToy link I've sent.
  • In the second render target you bind the texture from the first one - this is what Buf B is doing in ShaderToy link I've sent. It does some blurring and weighting of the values
  • Render a fullscreen quad with lens flare shader into backbuffer, bind 2 textures from both render targets. And you're doing basically what Image is doing in ShaderToy. Calculating lens flare based on texture from second render target, and adding the result to the texture from first render target. This value is written out

I saw the posted code here - while it's possible for me (or other members who have years of experience in graphics rendering) to fix that, such way has few major problems:

  1. It would take quite a long time (and especially throughout the week, most of us have work or run businesses) - so we simply don't have enough time to do that
  2. It wouldn't have a point - when you're trying to implement new features, you need to understand them - and concepts why it is done this way (which is why I pointed out the links above - as they explain why and what to do)

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

  • 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!