Page 1 of 2

Shader Coding Help for New Vegas 0.141

Posted: 28 Jan 2013, 15:38
by Malonn
Hey,
I'm trying to work around what I believe to be bugs with the latest released version of the New Vegas ENB (version 0.141). It seems the common way to separate day and night in the "enbeffect.fx" file was to use the linear interpolation command, like so:

Code: Select all

float EAdaptationMaxV4=lerp(lerp(EAdaptationMaxV4Day, EAdaptationMaxV4Night, ENightDayFactor), EAdaptationMaxV4Interior, EInteriorFactor);
	float EAdaptationMinV4=lerp(lerp(EAdaptationMinV4Day, EAdaptationMinV4Night, ENightDayFactor), EAdaptationMinV4Interior, EInteriorFactor);
Boris said that this looks good and should work. BUT, it doesn't. The variables that should be separate, like "EAdaptationMaxV4Day" and "EAdaptationMaxV4Night", are not separate. They stack. So increasing the night variable also effects the days, just like the day variable does. So, I managed to work around this, as the function "ENightDayFactor" does work properly. So, this is what I had to do to make it work properly (night and day settings are separate, as well as interior (mostly, more on that later - the reason for posting):

Code: Select all

if (ENightDayFactor) {
	color.xyz=color.xyz/(grayadaptation*EAdaptationMaxV2Day+EAdaptationMinV2Day);	//*tempF1.x
	color.xyz*=EBrightnessV2Day;
	color.xyz+=0.000001;
	float3 xncol=normalize(color.xyz);
	float3 scl=color.xyz/xncol.xyz;
	scl=pow(scl, EIntensityContrastV2Day);
	xncol.xyz=pow(xncol.xyz, EColorSaturationV2Day);
	color.xyz=scl*xncol.xyz;
	float lumamax=EToneMappingOversaturationV2Day;
	color.xyz=(color.xyz * (1.0 + color.xyz/lumamax))/(color.xyz + EToneMappingCurveV2Day);
	} else {
	color.xyz=color.xyz/(grayadaptation*EAdaptationMaxV2Night+EAdaptationMinV2Night);
	color.xyz*=EBrightnessV2Night;
	color.xyz+=0.000001;
	float3 xncol=normalize(color.xyz);
	float3 scl=color.xyz/xncol.xyz;
	scl=pow(scl, EIntensityContrastV2Night);
	xncol.xyz=pow(xncol.xyz, EColorSaturationV2Night);
	color.xyz=scl*xncol.xyz;
	float lumamax=EToneMappingOversaturationV2Night;
	color.xyz=(color.xyz * (1.0 + color.xyz/lumamax))/(color.xyz + EToneMappingCurveV2Night);
	} 
	if (EInteriorFactor) {
	color.xyz=color.xyz/(grayadaptation*EAdaptationMaxV2Interior+EAdaptationMinV2Interior);
	color.xyz*=EBrightnessV2Interior;
	color.xyz+=0.000001;
	float3 xncol=normalize(color.xyz);
	float3 scl=color.xyz/xncol.xyz;
	scl=pow(scl, EIntensityContrastV2Interior);
	xncol.xyz=pow(xncol.xyz, EColorSaturationV2Interior);
	color.xyz=scl*xncol.xyz;
	float lumamax=EToneMappingOversaturationV2Interior;
	color.xyz=(color.xyz * (1.0 + color.xyz/lumamax))/(color.xyz + EToneMappingCurveV2Interior);
	}
The preceding works properly, separating day and night. One does not effect the other. The problem I've run into is that the NIGHT settings effect interiors too. The DAY doesn't, only the night. So, how can I separate interior from night?? I've tried several things, including changing variable names, nullifying a settings by doing the opposite of what is in the rest of the code, changing flow control commands, etc. I have to assume it's a bug with ENB, but I don't know.
For some reason, any night setting also does the same to interiors. Increasing "EBrightnessV2Night", for example, increases brightness in interiors as well, just like "EBrightnessV2Interior" does, in this example.

Any help would be greatly appreciated.

Mark

Re: Shader Coding Help for New Vegas 0.141

Posted: 28 Jan 2013, 16:46
by mindflux
I'm not quite sure what you're trying to achieve here - i.e. why do you want to completely separate night and day settings? For ENightDayFactor, 1 is 100% daytime and 0 100% night-time. Anything between, like dawn and dusk, would be something in-between, and obviously for smooth transitions between different times of day it would be preferable to interpolate the values. Of course one consequence of interpolating is that the values will always somewhat affect each other especially when ENightDayFactor is not 100% or 0%.

Currently the night values affect interiors because of the logic you've applied is flawed: if ENightDayFactor = day, use day values, else use night values.

Re: Shader Coding Help for New Vegas 0.141

Posted: 28 Jan 2013, 17:31
by Malonn
Okay, so the night and day values are not definitive, like day and night only?? There are in-between's? Like, let's say 6:30AM game time is dawn, then ENightDayFactor doesn't == 1?? It equals (just pulling this out of thin air) 0.75? If that's the case, I didn't know that. And, I don't think I like that.

I was trying to separate night from day because I thought it was a simple "1" or "0", and that it wasn't working properly. So, I was testing different settings at @ 10:00AM. Both night and day variables effected the scene. So, you're saying it was because ENightDayFactor may not have been a "1" at that time? This is from the perspective of using the "lerp" function. But, if that's the case, why when I set the code shown in my OP, did 10:00AM register as day, and not somewhere in-between? I just want separate values for greater control over the scene. Better tweaking and end result, IMHO. I guess it's just a matter of taste, but I want separate values.

So, on to the Night variables effecting the interior: I tried setting and "else if" statement. Like so:

Code: Select all

If (ENightDayFactor) {
         <do stuff>
         } else if (ENightDayFactor == 0) {
         <do stuff>
         } else {
         if (EInteriorFactor) {
         <do stuff>
...but that didn't change anything. Night variables still effected interiors. Should I have excluded the last "else" and just started with an "if"? Like so:

Code: Select all

If (ENightDayFactor) {
         <do stuff>
         } else if (ENightDayFactor == 0) {
         <do stuff>
         }
         if (EInteriorFactor) {
         <do stuff>
If not, could you maybe give me an example? This is my first dabble into HLSL.

Thanks,
Mark

Re: Shader Coding Help for New Vegas 0.141

Posted: 28 Jan 2013, 18:19
by mindflux
Yes, the values are not definite, and in practice I think (don't remember for sure, though) they are rarely 0 or 1, but something in-between instead. The main problem with the way you want to set things up with if statement is that you will obviously have abrupt changes in the image when the values change without interpolation. Nevertheless, if you still want to pursue your approach, it would be better to use < and > for evaluation than ==.

Does New Vegas already feature day and night cycle for interiors? In case it does, I guess a fool-proof way to separate everything is like this:

Code: Select all

if (ENightDayFactor < 0.5) {
     if (EInteriorFactor == 1) {
     ....(interior night code)
     } else {
     ....(exterior night code) }
     }
if (ENightDayFactor > 0.5) {
     if (EInteriorFactor == 1) {
     ...(interior day code)
     } else {
     ....(exterior day code) }
     }
As you can see, nighttime values are used when detector value goes below 0.5. But again, it's not going to work very well this way. Also, branching is not good for performance.

Re: Shader Coding Help for New Vegas 0.141

Posted: 28 Jan 2013, 19:24
by Malonn
Okay. I did not know the values are not a absolute 1 or 0. That must be why, when using the "lerp" function before (as many people use this with Skyrim and New Vegas), during the day in-game the "night" variables didn't effect the scene as strongly as the "day" variables. ENightDayFactor must have been somewhere in-between a "0" and a "1". That makes it hard to tweak, if you try to separate day and night settings. Probably why Boris didn't separate them to begin with. Plus, games like New Vegas have weather patterns, which probably trigger a "0" through "1" like a clear night sky and clear day sky do. Well, I appreciate your help.

In your opinion, do you think there should be separate day and night values? Oh, and no, New Vegas doesn't have separate day and night interior values, just exterior.

Re: Shader Coding Help for New Vegas 0.141

Posted: 28 Jan 2013, 20:43
by mindflux
Yes, it does get somewhat complicated. The way it all works is that ENB reads the background color of the weather to detect the time of day - the darker the color, the more emphasis is given to night-time values and vice versa. This means that at least in Skyrim some weathers such as rainstorm will be very dark without carefully designed settings and/or additional tweaks to daytime detector.

Even so, I do like to have separate values for night and day because of the additional versatility it gives. I still try to aim pretty similar values because significant discrepancies will most likely cause issues balancing dawn and dusk as well as lead to an inconsistent look between night and day. Regarding tweaking, I've found out it's probably best to tweak a) at midday to set up values for daytime, and b) at midnight, to do the same for nights. If you don't have wildly different values, it shouldn't be too difficult to find the sweet spot. Of course it's a good idea to constantly switch between day and night and review changes.

Re: Shader Coding Help for New Vegas 0.141

Posted: 28 Jan 2013, 22:41
by Malonn
The time of day does seem to make sense. Noon for day, midnight for night. The weather mod I use also allows you to force certain weathers, like clouds, sunny, rain, snow, etc. So that should be helpful in my quest. Now back to the problems I'm facing. I haven't yet implemented your recommendations, but tried a couple of things with what I already was doing. It would seem that setting

Code: Select all

if (ENightDayFactor == 0)
             <do stuff>
The lines would only apply when it is certainly night. So why does the interiors get effected by the night variables during the day? That's when my testing took place, during the day. I could understand if it was at night and inside. So, I tested at 10:15AM and at 1:00PM. Interiors were still effected by night variables at both times. I just don't really understand.

<If night...do stuff...>
<if interior...do stuff...>

If I was using the "lerp" function I could understand. I do understand. But it seems the code I set is absolute night or absolute day. I don't know. I'm hoping Boris can make a quick statement, but it seems he quit active development of New Vegas ENB.

Anyway, I'm going to implement your suggestions and see if they make a difference. You know a heck of a lot more about it than I do.

Thanks again for your help,
Mark

Re: Shader Coding Help for New Vegas 0.141

Posted: 28 Jan 2013, 23:06
by mindflux
Well, what I know is just what I've learned (actually, what I *think* I have learned) from working with ENB, but I can't code even with my left hand, so it's a good idea to take my suggestions with a grain of salt.

The reason why interiors are affected in your implementation is because the value that ENightDayFactor gets has nothing to do with whether the location is detected as interior or not - if ENightDayFactor == 0 or 1, it doesn't matter, for all ENB knows it could still be an interior location - that's why you have to evaluate both for reliable detection, like I did in my code example.

Re: Shader Coding Help for New Vegas 0.141

Posted: 29 Jan 2013, 01:05
by Malonn
Okay. I think I understand. It would probably have been simpler if I just tested the code out, but I still haven't. Will do right after I post this.

So, ENB doesn't detect night and day and interior separately? ...I'm just going to spin myself around here. Let me test your code and see what happens.

Re: Shader Coding Help for New Vegas 0.141

Posted: 29 Jan 2013, 02:41
by Malonn
Okay, mindflux, here are the results. Following the code you suggested...

Code: Select all

If Daytime
             If Interior
                  <Interior Daytime stuff?
             Else
                  <Daytime exterior stuff>

          If Nightime
               If Interior
                    <Interior Nightime stuff>
               Else
                    <Nightime exterior stuff
That does indeed separate interior variables from exterior variables. Those are distinct. BUT, it gets wonky from there. The in-game daytime variables don't effect the daytime scene, they effect the nighttime scene. And vice versa (Night variables effect daytime scene). But it gets weirder: I can alter the day with nightime variables (no problem, just change variable names, right...no) but I can only reverse the change to one variable by increasing the opposite variable settings. So, example:

Code: Select all

float nightbrightness=10
increases daytime brightness. But changing nightbrightness to 1 again doesn't reduce the scene brightness. I have to change the opposite equally:

Code: Select all

float daybrightness=10
decreases the daytime scene brightness back to default. Weird weird weird. I'm lost. Hopefully you are not.

Thanks again,
Mark