Is it possible to make lens texture be calculated in LDR instead of HDR, but still be affected by bloom? So now matter how high the HDR value is, the texture won't get clipped, only get wider. I am asking, because sometimes it looks like this:
and as you can see, the center is pretty much completely clipped because of high bloom and high HDR value of sun reflection in the mirror-like puddle.
And also, it would be nice if the lens texture could be calculated in higher resultion than the default 1024x1024, it's sometimes to low and you can see the upsampling artefacts.
[F4] Question regarding the lens effect
- Author
- Message
-
Offline
- *sensei*
- Posts: 341
- Joined: 27 Dec 2011, 21:33
- Location: Poland, Gdańsk
[F4] Question regarding the lens effect
Last edited by MaxG3D on 20 Sep 2016, 21:46, edited 1 time in total.
_________________
OS: Windows 10
CPU: AMD R5 3600
RAM: Corsair DDR4 16GB 3200MHz Vengeance
GPU: AMD Radeon 5700 XT
Sound Card: X-FI Titanium HD
Mobo: ASRock X370 Pro4
Monitor: M340CLZ 34" 3440x1440 100HZ AMD FREE Sync Curved Monitor
OS: Windows 10
CPU: AMD R5 3600
RAM: Corsair DDR4 16GB 3200MHz Vengeance
GPU: AMD Radeon 5700 XT
Sound Card: X-FI Titanium HD
Mobo: ASRock X370 Pro4
Monitor: M340CLZ 34" 3440x1440 100HZ AMD FREE Sync Curved Monitor
-
Offline
- *blah-blah-blah maniac*
- Posts: 17557
- Joined: 27 Dec 2011, 08:53
- Location: Rather not to say
Re: [F4] Question regarding the lens effect
I don't know what's the problem. Want ldr, then set res=saturate(res); or same in each input of texture. Resolution is set by render targets used, there are two of them have screen size, so it's not a problem.
_________________
i9-9900k, 64Gb RAM, RTX 3060 12Gb, Win7
i9-9900k, 64Gb RAM, RTX 3060 12Gb, Win7
-
Offline
- *sensei*
- Posts: 341
- Joined: 27 Dec 2011, 21:33
- Location: Poland, Gdańsk
Re: [F4] Question regarding the lens effect
I want the lens texture to stay in it's original 0-255 range so that I don't lose the details,when looking at a very high HDR values. So no matter how high the HDR is, be it 1.0 or 10000, it always looks the same, as if it was just a simple overlay with the only difference being that the lens should still apply only to the bloom area, rather than the whole image.
Anyways, I tried both, setting the render target to either RGBA32/64f or adding the "res=saturate(res);" but non of them work, no compile error or anything, the lens just doesn't do anything anymore.
Default:
Edited:
Anyways, I tried both, setting the render target to either RGBA32/64f or adding the "res=saturate(res);" but non of them work, no compile error or anything, the lens just doesn't do anything anymore.
Default:
Code: Select all
//add mask
{
coord=IN.txcoord0.xy;
coord.y*=ScreenSize.w;//remove stretching of image
float4 mask=LensMaskTexture.Sample(Sampler1, coord.xy);
float3 templens=RenderTarget1024.Sample(Sampler1, IN.txcoord0.xy);
float maxlens=max(templens.x, max(templens.y, templens.z));
float tempnor=(maxlens/(1.0+maxlens));
tempnor=pow(tempnor, LensParameters.w);
templens.xyz*=tempnor * LensParameters.z;
res.xyz+=mask.xyz * templens.xyz;
}
return res;
}
float4 PS_MixSkyrimLens(VS_OUTPUT_POST IN, float4 v0 : SV_Position0) : SV_Target
{
float4 res;
float4 color;
res=RenderTarget512.Sample(Sampler1, IN.txcoord0.xy);
res=max(res, 0.0);
res=min(res, 16384.0);
res.w=1.0;
return res;
}
Code: Select all
//add mask
{
coord=IN.txcoord0.xy;
coord.y*=ScreenSize.w;//remove stretching of image
float4 mask=LensMaskTexture.Sample(Sampler1, coord.xy);
float3 templens=RenderTarget1024.Sample(Sampler1, IN.txcoord0.xy);
float maxlens=max(templens.x, max(templens.y, templens.z));
float tempnor=(maxlens/(1.0+maxlens));
tempnor=pow(tempnor, LensParameters.w);
templens.xyz*=tempnor * LensParameters.z;
res.xyz+=mask.xyz * templens.xyz;
res=saturate(res);
}
return res;
}
float4 PS_MixSkyrimLens(VS_OUTPUT_POST IN, float4 v0 : SV_Position0) : SV_Target
{
float4 res;
float4 color;
res=RenderTargetRGBA32.Sample(Sampler1, IN.txcoord0.xy);
// res=RenderTargetRGBA64f.Sample(Sampler1, IN.txcoord0.xy);
res=max(res, 0.0);
res=min(res, 16384.0);
res.w=1.0;
return res;
}
_________________
OS: Windows 10
CPU: AMD R5 3600
RAM: Corsair DDR4 16GB 3200MHz Vengeance
GPU: AMD Radeon 5700 XT
Sound Card: X-FI Titanium HD
Mobo: ASRock X370 Pro4
Monitor: M340CLZ 34" 3440x1440 100HZ AMD FREE Sync Curved Monitor
OS: Windows 10
CPU: AMD R5 3600
RAM: Corsair DDR4 16GB 3200MHz Vengeance
GPU: AMD Radeon 5700 XT
Sound Card: X-FI Titanium HD
Mobo: ASRock X370 Pro4
Monitor: M340CLZ 34" 3440x1440 100HZ AMD FREE Sync Curved Monitor
-
Offline
- *blah-blah-blah maniac*
- Posts: 17557
- Joined: 27 Dec 2011, 08:53
- Location: Rather not to say
Re: [F4] Question regarding the lens effect
No, it's wrong code and what you ask may be interpreted in various ways. Lens shader result is output as texture in enbeffect.fx, so you need first to set it as primary output and see nothing else on screen, except it, otherwise you will be fooled by tonemapping, bloom or anything else in there. You may even create there frac() function to see if lens texture goes above 1.0 by intensity.
Before:
After:
Before:
Code: Select all
//add mask
{
coord=IN.txcoord0.xy;
coord.y*=ScreenSize.w;//remove stretching of image
float4 mask=LensMaskTexture.Sample(Sampler1, coord.xy);
float3 templens=RenderTarget128.Sample(Sampler1, IN.txcoord0.xy);
float maxlens=max(templens.x, max(templens.y, templens.z));
float tempnor=(maxlens/(1.0+maxlens));
tempnor=pow(tempnor, LensParameters.w);
templens.xyz*=tempnor * LensParameters.z;
res.xyz+=mask.xyz * templens.xyz;
}
Code: Select all
//add mask
{
coord=IN.txcoord0.xy;
coord.y*=ScreenSize.w;//remove stretching of image
float4 mask=LensMaskTexture.Sample(Sampler1, coord.xy);
float3 templens=RenderTarget128.Sample(Sampler1, IN.txcoord0.xy);
float maxlens=max(templens.x, max(templens.y, templens.z));
float tempnor=(maxlens/(1.0+maxlens));
tempnor=pow(tempnor, LensParameters.w);
templens.xyz*=tempnor * LensParameters.z;
res.xyz=saturate(res.xyz);
res.xyz+=mask.xyz * saturate(templens.xyz);
}
_________________
i9-9900k, 64Gb RAM, RTX 3060 12Gb, Win7
i9-9900k, 64Gb RAM, RTX 3060 12Gb, Win7
-
Offline
- *sensei*
- Posts: 341
- Joined: 27 Dec 2011, 21:33
- Location: Poland, Gdańsk
Re: [F4] Question regarding the lens effect
Oh, I see, the whole shader would basically have to be different. Thank for the help Boris, sadly it's out of my scope to wright such a shader from scratch but maybe one of the shader magicians like Marty McFly or Kingeric will be able to write such a code.
Again, thank you very much for the help.
Again, thank you very much for the help.
_________________
OS: Windows 10
CPU: AMD R5 3600
RAM: Corsair DDR4 16GB 3200MHz Vengeance
GPU: AMD Radeon 5700 XT
Sound Card: X-FI Titanium HD
Mobo: ASRock X370 Pro4
Monitor: M340CLZ 34" 3440x1440 100HZ AMD FREE Sync Curved Monitor
OS: Windows 10
CPU: AMD R5 3600
RAM: Corsair DDR4 16GB 3200MHz Vengeance
GPU: AMD Radeon 5700 XT
Sound Card: X-FI Titanium HD
Mobo: ASRock X370 Pro4
Monitor: M340CLZ 34" 3440x1440 100HZ AMD FREE Sync Curved Monitor
-
Offline
- *master*
- Posts: 119
- Joined: 05 Jan 2012, 22:34
- Location: France
Re: [F4] Question regarding the lens effect
That's quite confusing
Any pictures of how it should look like?
Do you want the bloom / lens flare to be clamped or the dirt texture itself ?
Why don't you try to mix your texture inside the enbeffect.fx and apply that after tonemapping or something ? Or even idk change the gamma of the tex?
It's hard to know what you're trying to achieve to help you properly.
(Unless I just really didn't get it and i'm dumb as f*ck )
Any pictures of how it should look like?
Do you want the bloom / lens flare to be clamped or the dirt texture itself ?
Why don't you try to mix your texture inside the enbeffect.fx and apply that after tonemapping or something ? Or even idk change the gamma of the tex?
It's hard to know what you're trying to achieve to help you properly.
(Unless I just really didn't get it and i'm dumb as f*ck )
-
Offline
- *sensei*
- Posts: 341
- Joined: 27 Dec 2011, 21:33
- Location: Poland, Gdańsk
Re: [F4] Question regarding the lens effect
Icelaglace, I want the dirt texture to be clamped, so no matter how bright the light is, it still just the LDR texture. Otherwise, if you look at a very bright light, the texture itself can sometimes turn into clipped, full white texture. Currently, it's hard to fine tune it with intensity/power so that it looks correct in any condition. If I set the intensity too low, so that it doesn't get clipped, it then doesn't apply to smaller lights.
You know how in BF3 or the latest Cryengine, the dirt texture is not a part of a bloom shader, but just a flag for certain lights? So no matter how far from the light you are, the player can still see the dirt on the camera, for that certain light? That's kind what I had in mind. With dirt texture calculated in LDR, it would always look the same, always with the same intensity, the bloom would only mask the dirt texture, not set it's intensity. And I think Boris got my idea right, with making the dirt texture as a primary output of enbeffect, that latter on is hidden in the parts of the player viewport that don't have any bloom, I just have no idea how to write that in HLSL.
Hope that explains it a bit better
You know how in BF3 or the latest Cryengine, the dirt texture is not a part of a bloom shader, but just a flag for certain lights? So no matter how far from the light you are, the player can still see the dirt on the camera, for that certain light? That's kind what I had in mind. With dirt texture calculated in LDR, it would always look the same, always with the same intensity, the bloom would only mask the dirt texture, not set it's intensity. And I think Boris got my idea right, with making the dirt texture as a primary output of enbeffect, that latter on is hidden in the parts of the player viewport that don't have any bloom, I just have no idea how to write that in HLSL.
Hope that explains it a bit better
_________________
OS: Windows 10
CPU: AMD R5 3600
RAM: Corsair DDR4 16GB 3200MHz Vengeance
GPU: AMD Radeon 5700 XT
Sound Card: X-FI Titanium HD
Mobo: ASRock X370 Pro4
Monitor: M340CLZ 34" 3440x1440 100HZ AMD FREE Sync Curved Monitor
OS: Windows 10
CPU: AMD R5 3600
RAM: Corsair DDR4 16GB 3200MHz Vengeance
GPU: AMD Radeon 5700 XT
Sound Card: X-FI Titanium HD
Mobo: ASRock X370 Pro4
Monitor: M340CLZ 34" 3440x1440 100HZ AMD FREE Sync Curved Monitor
-
Offline
- *blah-blah-blah maniac*
- Posts: 530
- Joined: 30 Jan 2012, 13:18
Re: [F4] Question regarding the lens effect
I think the issue here is the blending mode. An already bright color + a tiny bit of lens dirt results in clipping, no matter how weak the lens effect is.
In older games, those dirt effects are not drawn with bloom as mask but as a sprite, not adding up to color but replacing it. Bright sprite on bright color does not result in brighter color, no clipping.
Cryengine etc just use different blending math to combine color and lens effect, the masks for those effects is still bloom texture, or at least it looka like that to me.
For non-clip, soft bloom, I use result = 1-(1-color)*(1-bloom) after tonemap (bloom needs separate tonemap), doing the same with lens instead of bloom would create the desired look.
Or try the thing Boris did(clipping only when source image is bright already), instead of
res.xyz+=mask.xyz * templens.xyz;
Do
res.xyz+=mask.xyz * saturate(templens.xyz);
Alternatively if you want more control
res.xyz+=mask.xyz * pow(saturate(templens.xyz), factorA) * factorB;
Set factorA to any number <1 for a more widespread lens dirt effect and factorB to anything <1 to weaken the effect without losing its range.
Maybe this is total bullshit it's 2:30 am and I'm tired.
In older games, those dirt effects are not drawn with bloom as mask but as a sprite, not adding up to color but replacing it. Bright sprite on bright color does not result in brighter color, no clipping.
Cryengine etc just use different blending math to combine color and lens effect, the masks for those effects is still bloom texture, or at least it looka like that to me.
For non-clip, soft bloom, I use result = 1-(1-color)*(1-bloom) after tonemap (bloom needs separate tonemap), doing the same with lens instead of bloom would create the desired look.
Or try the thing Boris did(clipping only when source image is bright already), instead of
res.xyz+=mask.xyz * templens.xyz;
Do
res.xyz+=mask.xyz * saturate(templens.xyz);
Alternatively if you want more control
res.xyz+=mask.xyz * pow(saturate(templens.xyz), factorA) * factorB;
Set factorA to any number <1 for a more widespread lens dirt effect and factorB to anything <1 to weaken the effect without losing its range.
Maybe this is total bullshit it's 2:30 am and I'm tired.
-
Offline
- *blah-blah-blah maniac*
- Posts: 17557
- Joined: 27 Dec 2011, 08:53
- Location: Rather not to say
Re: [F4] Question regarding the lens effect
Yeah, but blending mode can be applied only in enbeffect.fx at the end of it, after tonemapping, otherwise it have a big chance to corrupt everything about the same way. The problem require many things to be changed in case of making it fully ldr (also mask and lens reflections must be split).
_________________
i9-9900k, 64Gb RAM, RTX 3060 12Gb, Win7
i9-9900k, 64Gb RAM, RTX 3060 12Gb, Win7
-
Offline
- *sensei*
- Posts: 341
- Joined: 27 Dec 2011, 21:33
- Location: Poland, Gdańsk
Re: [F4] Question regarding the lens effect
Marty code worked, no more clipping but yeah, the blending is still not suitable for such solution, higher lens dirt intensity make the image foggy. Nonetheless, it's already miles better without clipping, so thanks a lot guys for all the help
_________________
OS: Windows 10
CPU: AMD R5 3600
RAM: Corsair DDR4 16GB 3200MHz Vengeance
GPU: AMD Radeon 5700 XT
Sound Card: X-FI Titanium HD
Mobo: ASRock X370 Pro4
Monitor: M340CLZ 34" 3440x1440 100HZ AMD FREE Sync Curved Monitor
OS: Windows 10
CPU: AMD R5 3600
RAM: Corsair DDR4 16GB 3200MHz Vengeance
GPU: AMD Radeon 5700 XT
Sound Card: X-FI Titanium HD
Mobo: ASRock X370 Pro4
Monitor: M340CLZ 34" 3440x1440 100HZ AMD FREE Sync Curved Monitor