DNI Multiple Palettes?

share shaders here
Post Reply
  • Author
  • Message
Offline
Posts: 66
Joined: 08 May 2014, 00:00

DNI Multiple Palettes?

Hi, I was wondering if it is possible to use separate palette textures for days, nights, and interiors.

I tried something that didn't work but maybe if I post it here someone may be able to point out some mistakes.

Textures first

Code: Select all

texture2D PaletteDay
	<
		string ResourceName="PaletteDay.bmp";
	>;	//ENB Palette Day

texture2D PaletteNight		
	<
		string ResourceName="PaletteNight.bmp";
	>;	//ENB Palette Night	

texture2D PaletteInterior
	<
		string ResourceName="PaletteInterior.bmp";
	>;	//ENB PaletteInterior

sampler2D SamplerPaletteDayTexture = sampler_state
	{
		Texture		=	<PaletteDay>;
		MinFilter	=	LINEAR;
		MagFilter	=	LINEAR;
		MipFilter	= 	NONE;
		AddressU	=	Wrap;
		AddressV	=	Wrap;
		SRGBTexture	=	FALSE;
		MaxMipLevel	=	0;
		MipMapLodBias	=	0;
	};

sampler2D SamplerPaletteNightTexture = sampler_state
	{
		Texture		=	<PaletteNight>;
		MinFilter	=	LINEAR;
		MagFilter	=	LINEAR;
		MipFilter	= 	NONE;
		AddressU	=	Wrap;
		AddressV	=	Wrap;
		SRGBTexture	=	FALSE;
		MaxMipLevel	=	0;
		MipMapLodBias	=	0;
	}; 

sampler2D SamplerPaletteInteriorTexture = sampler_state
	{
		Texture		=	<PaletteInterior>;
		MinFilter	=	LINEAR;
		MagFilter	=	LINEAR;
		MipFilter	= 	NONE;
		AddressU	=	Wrap;
		AddressV	=	Wrap;
		SRGBTexture	=	FALSE;
		MaxMipLevel	=	0;
		MipMapLodBias	=	0;
	};

Then palette color correction code

Code: Select all

#if	(ENightDayFactor == 1 & EInteriorFactor == 0)

	float3	palette;
		color.rgb	=	saturate(color.rgb);
	float3	brightness	=	Adaptation.xyz;						//tex2D(_s4, 0.5);//adaptation luminance
		brightness	=	(brightness/(brightness+1.0));				//new version
		brightness	=	max(brightness.x, max(brightness.y, brightness.z));	//new version
	float4	uvsrc		=	0.0;
		uvsrc.y		=	brightness.r;
		uvsrc.x		=	color.r;
		palette.r	=	tex2Dlod(SamplerPaletteDayTexture, uvsrc).r;
		uvsrc.x		=	color.g;
		uvsrc.y		=	brightness.g;
		palette.g	=	tex2Dlod(SamplerPaletteDayTexture, uvsrc).g;
		uvsrc.x		=	color.b;
		uvsrc.y		=	brightness.b;
		palette.b	=	tex2Dlod(SamplerPaletteDayTexture, uvsrc).b;
		color.rgb	=	palette.rgb;

	#elif	(ENightDayFactor == 0 & EInteriorFactor == 0)

	float3	palette;
		color.rgb	=	saturate(color.rgb);
	float3	brightness	=	Adaptation.xyz;						//tex2D(_s4, 0.5);//adaptation luminance
		brightness	=	(brightness/(brightness+1.0));				//new version
		brightness	=	max(brightness.x, max(brightness.y, brightness.z));	//new version
	float4	uvsrc		=	0.0;
		uvsrc.y		=	brightness.r;
		uvsrc.x		=	color.r;
		palette.r	=	tex2Dlod(SamplerPaletteNightTexture, uvsrc).r;
		uvsrc.x		=	color.g;
		uvsrc.y		=	brightness.g;
		palette.g	=	tex2Dlod(SamplerPaletteNightTexture, uvsrc).g;
		uvsrc.x		=	color.b;
		uvsrc.y		=	brightness.b;
		palette.b	=	tex2Dlod(SamplerPaletteNightTexture, uvsrc).b;
		color.rgb	=	palette.rgb;

	#elif	(ENightDayFactor == 1 & EInteriorFactor == 1)

	float3	palette;
		color.rgb	=	saturate(color.rgb);
	float3	brightness	=	Adaptation.xyz;						//tex2D(_s4, 0.5);//adaptation luminance
		brightness	=	(brightness/(brightness+1.0));				//new version
		brightness	=	max(brightness.x, max(brightness.y, brightness.z));	//new version
	float4	uvsrc		=	0.0;
		uvsrc.y		=	brightness.r;
		uvsrc.x		=	color.r;
		palette.r	=	tex2Dlod(SamplerPaletteInteriorTexture, uvsrc).r;
		uvsrc.x		=	color.g;
		uvsrc.y		=	brightness.g;
		palette.g	=	tex2Dlod(SamplerPaletteInteriorTexture, uvsrc).g;
		uvsrc.x		=	color.b;
		uvsrc.y		=	brightness.b;
		palette.b	=	tex2Dlod(SamplerPaletteInteriorTexture, uvsrc).b;
		color.rgb	=	palette.rgb;
	
	#elif	(ENightDayFactor == 0 & EInteriorFactor == 1)

	float3	palette;
		color.rgb	=	saturate(color.rgb);
	float3	brightness	=	Adaptation.xyz;						//tex2D(_s4, 0.5);//adaptation luminance
		brightness	=	(brightness/(brightness+1.0));				//new version
		brightness	=	max(brightness.x, max(brightness.y, brightness.z));	//new version
	float4	uvsrc		=	0.0;
		uvsrc.y		=	brightness.r;
		uvsrc.x		=	color.r;
		palette.r	=	tex2Dlod(SamplerPaletteInteriorTexture, uvsrc).r;
		uvsrc.x		=	color.g;
		uvsrc.y		=	brightness.g;
		palette.g	=	tex2Dlod(SamplerPaletteInteriorTexture, uvsrc).g;
		uvsrc.x		=	color.b;
		uvsrc.y		=	brightness.b;
		palette.b	=	tex2Dlod(SamplerPaletteInteriorTexture, uvsrc).b;
		color.rgb	=	palette.rgb;

	#endif
I may just not understand how ENightDayFactor or EInteriorFactor works...

Offline
User avatar
*master*
Posts: 229
Joined: 21 Feb 2013, 03:21
Location: Los Angeles, CA

Re: DNI Multiple Palettes?

From what I can tell by a quick look, you can't use #if statements like that with ENightDayFactor and EInteriorFactor. The # means it's a preprocessor directive and requires a compile to be evaluated. The shader only compiles once while the game loads or if you force it with <apply changes>. For it to work, you would need to sample all 3 palettes and blend between them based on the DNI. Probably like this:

Code: Select all

 float3   paletteD;
 float3   paletteN;
 float3   paletteI;
      color.rgb   =   saturate(color.rgb);
   float3   brightness   =   Adaptation.xyz;                  //tex2D(_s4, 0.5);//adaptation luminance
      brightness   =   (brightness/(brightness+1.0));            //new version
      brightness   =   max(brightness.x, max(brightness.y, brightness.z));   //new version
   float4   uvsrc      =   0.0;
      uvsrc.y      =   brightness.r;
      uvsrc.x      =   color.r;
      paletteD.r   =   tex2Dlod(SamplerPaletteDayTexture, uvsrc).r;
     paletteN.r   =   tex2Dlod(SamplerPaletteNightTexture, uvsrc).r;
     paletteI.r   =   tex2Dlod(SamplerPaletteInteriorTexture, uvsrc).r;
      uvsrc.x      =   color.g;
      uvsrc.y      =   brightness.g;
      paletteD.g   =   tex2Dlod(SamplerPaletteDayTexture, uvsrc).g;
    paletteN.g   =   tex2Dlod(SamplerPaletteNightTexture, uvsrc).g;
    paletteI.g   =   tex2Dlod(SamplerPaletteInteriorTexture, uvsrc).g;
      uvsrc.x      =   color.b;
      uvsrc.y      =   brightness.b;
      paletteD.b   =   tex2Dlod(SamplerPaletteDayTexture, uvsrc).b;
      paletteN.b   =   tex2Dlod(SamplerPaletteNightTexture, uvsrc).b;
      paletteI.b   =   tex2Dlod(SamplerPaletteInteriorTexture, uvsrc).b;

      color.rgb   =   lerp(lerp(paletteN, paletteD, ENightDayFactor), paletteI, EInteriorFactor);

_________________
i7-4970K 4.8ghz, 16gb ram, Geforce Titan X 12gb vram, win7

Offline
Posts: 66
Joined: 08 May 2014, 00:00

Re: DNI Multiple Palettes?

That looks like it makes more sense. I'll try it. Thanks.

Offline
User avatar
*sensei*
Posts: 446
Joined: 17 Apr 2014, 22:12
Location: Schweden

Re: DNI Multiple Palettes?

Sounds cool! But how would the transitions be like from day to night?
_________________
| i5 3350p @3.1 | 16 GB RAM | GTX1060 | Skyrim on SSD |
My Flickr
My Soundcloud
CGI ENB

Offline
User avatar
*blah-blah-blah maniac*
Posts: 506
Joined: 02 Aug 2013, 23:06
Location: New Hampshire, US

Re: DNI Multiple Palettes?

I am pretty sure JawZ already has something like this. I know he has made a two palette version which is for night/day (you can see samples of the palettes on his Nexus resources) and I have code from him that shows some of it as well. You might want to check in with him.
_________________
Intel Core i9-9900K CPU @ 3.6 GHz // GeForce RTX 2080 Ti VRAM 11GB // Win10 64 and 64GB Ram // Monitor 2560x1440@144

Offline
User avatar
*blah-blah-blah maniac*
Posts: 1938
Joined: 05 Mar 2012, 02:08

Re: DNI Multiple Palettes?

Boris showed me in a thread here at the forum that you can use the NightDayFactor in the default palette code instead of the eadapt/Adaptation function. And then create a single .bmp palette file with two different palette maps inside of that one .bmp file.

Which would allow for Night and Day to have different looking palettes.

Change this code segemnt in the default palette code;

Code: Select all

float3 brightness=eadapt.xyz;
To this;

Code: Select all

float3 brightness=ENightDayFactor;
And use a palette like this, first item in the download section includes a palette file setup for the altered code.
http://www.nexusmods.com/skyrim/mods/36720/?


Much simpler, coding wise, than what have been posted and theorized here.

there is also the option of adding your own new .bmp file through the use of some GUI annotations but that would end up visually with the same result as the method above.

Offline
Posts: 66
Joined: 08 May 2014, 00:00

Re: DNI Multiple Palettes?

Thanks for the replies. I will try those ideas.
Post Reply