Page 1 of 2
[F4] Question regarding the lens effect
Posted: 20 Sep 2016, 13:59
by MaxG3D
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.
Re: [F4] Question regarding the lens effect
Posted: 20 Sep 2016, 20:36
by ENBSeries
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.
Re: [F4] Question regarding the lens effect
Posted: 20 Sep 2016, 21:05
by MaxG3D
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:
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;
}
Edited:
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;
}
Re: [F4] Question regarding the lens effect
Posted: 20 Sep 2016, 21:46
by ENBSeries
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:
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;
}
After:
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);
}
Re: [F4] Question regarding the lens effect
Posted: 20 Sep 2016, 21:54
by MaxG3D
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.
Re: [F4] Question regarding the lens effect
Posted: 21 Sep 2016, 09:11
by icelaglace
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
)
Re: [F4] Question regarding the lens effect
Posted: 21 Sep 2016, 10:00
by MaxG3D
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
Re: [F4] Question regarding the lens effect
Posted: 22 Sep 2016, 00:13
by Marty McFly
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.
Re: [F4] Question regarding the lens effect
Posted: 22 Sep 2016, 09:04
by ENBSeries
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).
Re: [F4] Question regarding the lens effect
Posted: 22 Sep 2016, 11:59
by MaxG3D
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