Adding Lens Flare

Started by
11 comments, last by isu diss 6 years, 1 month ago

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)

Untitled.png

Untitled2.png

Advertisement

pls help me

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:

https://www.shadertoy.com/view/ls3czM

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.

My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com

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?

@Vilem Otte

Do I need to draw a separate quad? What should I do to the sky dome? How do I bind backbuffer as SRV?

pls answer my question @Vilem Otte cos I'm stuck at this point

 

 

 

Untitled.png

help me @Vilem Otteto implement what you said earlier in Direct3D11

No need to down vote on me. I asked cos I don't know.

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)

My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com

Thanks you@Vilem Otte. I worked it out. Is this right?

lensflare1.png

lensflare2.png

lensflare3.png

lensflare4.png

This topic is closed to new replies.

Advertisement