Enhanced Lenz Flare
- luluco250
- Topic Author
I was looking for a way to modify the lenz flare effect, so I ended up modifying it on my own.
In the part where there's:
distfact.x *= RFX_ScreenSizeFull.z;
for (int i=0; i<19; i++)
{
lfcoord.xy=lfoffset[i].x*distfact;
lfcoord.xy*=pow(2.0*length(float2(distfact.x,distfact.y)), lfoffset[i].y*3.5);
lfcoord.xy*=lfoffset[i].z;
lfcoord.xy=0.5-lfcoord.xy;
float2 tempfact = (lfcoord.xy-0.5)*2;
float templensmult = clamp(1.0-dot(tempfact,tempfact),0,1);
float3 lenstemp1 = dot(tex2Dlod(GFX_SamplerHDR1, float4(lfcoord.xy,0,1)).xyz,0.333);
#if (LENZ_DEPTH_CHECK == 1)
float templensdepth = tex2D(RFX_depthColor, lfcoord.xy).x;
if(templensdepth < 0.99999) lenstemp1 = 0;
#endif
lenstemp1 = max(0,lenstemp1.xyz - fLenzThreshold);
lenstemp1 *= lffactors[i].xyz*templensmult;
lenstemp += lenstemp1;
}
I've replaced with this:
#if (iLenzUseCustomDistance == 1)
distfact.x *= fLenzDistance;
distfact.y *= fLenzDistance;
#else
distfact.x *= RFX_ScreenSizeFull.z;
#endif
for (int i=0; i<iLenzFactors; i++)
{
lfcoord.xy=lfoffset[i].x*distfact;
lfcoord.xy*=pow(2.0*length(float2(distfact.x,distfact.y)), lfoffset[i].y*3.5);
lfcoord.xy*=lfoffset[i].z;
lfcoord.xy=0.5-lfcoord.xy;
float2 tempfact = (lfcoord.xy-0.5)*2;
float templensmult = clamp(1.0-dot(tempfact,tempfact),0,1);
float3 lenstemp1 = dot(tex2Dlod(GFX_SamplerHDR1, float4(lfcoord.xy,0,1)).xyz,0.333);
#if (LENZ_DEPTH_CHECK == 1)
float templensdepth = tex2D(RFX_depthColor, lfcoord.xy).x;
if(templensdepth < 0.99999) lenstemp1 = 0;
#endif
lenstemp1 = max(0,lenstemp1.xyz - fLenzThreshold);
lenstemp1 *= lffactors[i].xyz*templensmult;
lenstemp += lenstemp1;
}
Now the code can change the distance based on fLenzDistance (optionally, based on iLenzUseCustomDistance) and also can render less halos based on iLenzFactors, instead of only 19.
My objective with this was that I was experimenting with Witcher 1 and was looking for a a good-looking but subtle lens flare, since the game doesn't have depth buffer access outside of cutscenes I had to be a bit creative so it didn't look too overdone.
Here's how what I modified in GemFX.cfg:
////-------------//
///**LENZFLARE**///
//-------------////
#define USE_LENZFLARE 1 //[Bloom] //-Lenz Flare: Boris Vorontsov's Skyrim Lensflare with custom offsets, ported to MasterEffect.
//>Lenz Flare Settings<\\
#define LENZ_DEPTH_CHECK 0 //[0:1] //-If 1, only pixels with depth = 1 get lens flare, this prevents white objects from getting flare source which would normally happen in LDR
#define fLenzIntensity 3.0 //[0.2:3.0] //-power of lens flare effect
#define fLenzThreshold 0.85 //[0.6:1.0] //-Minimum brightness an object must have to cast lensflare
#define iLenzUseCustomDistance 1 //[0:1] //-Set to use a custom distance or a default "squared" area of the screen
#define fLenzDistance 1.5 //[0.1:1.0] //-Distance from the center, it is inversed meaning lower values will be far from the center of the screen, do not set to zero
#define iLenzFactors 3 //[1:19] //-Amount of lens flare halos, lower values will not feature the outer halos
I was using a mix of Ambient Lighting (plus fine-tuned adaptation and lens from it, replaced the lens texture with the generic light sprite) and chapman lens, but I wasn't too fond of the look chapman lens had.
I was tempted to try using lenz instead but I knew it was normally restricted to the center of the screen, and had very little customization options, so I studied the code a bit and came up with this solution. Hopefully it's clean enough, I have really no experience with shaders, only programming in general so this isn't exactly my expertise.
This is the final look I got and am quite satisfied with it:
Any comments and/or suggestions are much appreciated, as I said before this is my first time doing something like this so tell me if I did anything wrong.
Please Log in or Create an account to join the conversation.
- luluco250
- Topic Author
Please Log in or Create an account to join the conversation.
- luluco250
- Topic Author
Lenz default, 19 halos:
The setting I'm using, 3 halos:
It's not a problem for me to have little noticeable lens flare in the second image, because I want to have it very subtle and it looks very good at side angles like in my previously uploaded screenshots.
This is what the absolutely default effect looks like, with the default distance and the default 19 halos:
Please Log in or Create an account to join the conversation.
- jas01
I can have HBAO+ in this game. Interested?
Please Log in or Create an account to join the conversation.
- Marty McFly
Please Log in or Create an account to join the conversation.
- luluco250
- Topic Author
Uhm...the offsets and their count are intended to be freely selectable for the user, why making their control values global? The arrays for the lensflares currently hold 19 value pairs and the loop iterates 19 times for these 19 flares. You are free to modify those arrays and the loop count, the way the lensflare looks like is by no means fixed. You can replicate almost any lensflare with it. Besides, the lens flare scale is already controlled by one of the lensflare factors. Control values which are being stored by the lffactor array is deepness, curvature and inverse size. What you changed is the deepness. And why changing the aspect correction? Now the lensflare wideness is depending on the aspect ratio.
As I already explained shaders isn't my area of expertise so forgive me beforehand for lack of knowledge.
What I wanted to do originally was simply have a bit more customization on the lenz effect. I have also noticed that the actual ENB lenz flare isn't restricted to the aspect ratio, which is fine by me (and is what I prefer), neither is ambient light's lens effect nor chapman lens, so I really have no idea why lenz had this restriction.
Now I do understand what you mean with the 19 flares but tl;dr I was lazy and just happened to find a quick solution, if you can help me understand what exactly I got wrong it'd be better (given what my idea was originally). But too specific terms are kinda hard to comprehend, I'm sure you can understand.
* Off-topic
I can have HBAO+ in this game. Interested?
Nice but given that this game isn't exactly well optimized I fear too much FPS loss, I find it looks fine enough as it is right now (the only problem of this game is the models and animations for me), but thanks I'll be sure to check it out!
Please Log in or Create an account to join the conversation.
- Marty McFly
Please Log in or Create an account to join the conversation.
- luluco250
- Topic Author
Perhaps a better solution could be to scale up the shader to keep the 1x1 aspect ratio but cover the whole screen?
Regardless, I like the way it looks.
I'll do some experimenting and see if I can thoroughly enhance it.
Please Log in or Create an account to join the conversation.