Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //++++++++++++++++++++++++++++++++++++++++++++++++
- // Clouds from SA_DirectX 2.0
- // Copyright Boris Vorontsov / Maxim Dubinov (Makarus)
- // Editing and combining as well as cloud settings by AP84
- //++++++++++++++++++++++++++++++++++++++++++++++++
- //internal parameters, can be modified
- //+++++++++++++++++++++++++++++
- float EShadowAmount
- <
- string UIName="Lighting: ShadowAmount";
- string UIWidget="Spinner";
- float UIMin=0.0;
- float UIMax=1.0;
- > = {0.5};
- float4 tempF1; float4 tempF2; float4 tempF3;
- float4 ScreenSize; float4 Timer;float ENightDayFactor;
- float4 SunDirection; float EInteriorFactor; float FadeFactor; float FieldOfView;
- float4 MatrixVP[4]; float4 MatrixInverseVP[4]; float4 MatrixVPRotation[4]; float4 MatrixInverseVPRotation[4];
- float4 MatrixView[4];float4 MatrixInverseView[4];float4 CameraPosition;float GameTime;float4 CustomShaderConstants1[8];
- float4 WeatherAndTime;float4x4 MatrixWVP;float4x4 MatrixWVPInverse;float4x4 MatrixWorld; float4x4 MatrixProj;float4 FogParam;float4 FogFarColor;
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
- //Textures
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
- texture2D texEnv;
- texture2D texOriginal;
- texture2D texColor;
- texture2D texDepth;
- texture2D texNoise;
- texture2D texShadow;
- texture2D texNormal;
- texture2D texNs < string ResourceName="Noise.png"; >;
- texture2D texNs2 < string ResourceName="NoiseCd.png";>;
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
- //Sampler Inputs
- //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
- sampler2D SamplerEnv = sampler_state
- {
- Texture = <texEnv>;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- MipFilter = LINEAR;
- AddressU = Mirror;
- AddressV = Mirror;
- SRGBTexture=FALSE;
- MaxMipLevel=0;
- MipMapLodBias=0;
- };
- sampler2D SamplerOriginal = sampler_state
- {
- Texture = <texOriginal>;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- MipFilter = LINEAR;//NONE;
- AddressU = Clamp;
- AddressV = Clamp;
- SRGBTexture=FALSE;
- MaxMipLevel=0;
- MipMapLodBias=0;
- };
- sampler2D SamplerNormal = sampler_state
- {
- Texture = <texNormal>;
- MinFilter = Anisotropic;
- MagFilter = Anisotropic;
- MipFilter = LINEAR;
- AddressU = Wrap;
- AddressV = Wrap;
- SRGBTexture=FALSE;
- MaxMipLevel=0;
- MipMapLodBias=0;
- };
- sampler2D SamplerColor = sampler_state
- {
- Texture = <texColor>;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- MipFilter = NONE;
- AddressU = Clamp;
- AddressV = Clamp;
- SRGBTexture=TRUE;
- MaxMipLevel=2;
- MipMapLodBias=0;
- };
- sampler2D SamplerDepth = sampler_state
- {
- Texture = <texDepth>;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- MipFilter = LINEAR;
- AddressU = Wrap;
- AddressV = Wrap;
- AddressW = Wrap;
- SRGBTexture=TRUE;
- MaxMipLevel=1;
- MipMapLodBias=0;
- };
- sampler2D SamplerNoise = sampler_state
- {
- Texture = <texNoise>;
- MinFilter = POINT;
- MagFilter = POINT;
- MipFilter = NONE;
- AddressU = Wrap;
- AddressV = Wrap;
- SRGBTexture=FALSE;
- MaxMipLevel=2;
- MipMapLodBias=0;
- };
- sampler2D SamplerShadow = sampler_state
- {
- Texture = <texShadow>;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- MipFilter = NONE;//NONE;
- AddressU = Clamp;
- AddressV = Clamp;
- SRGBTexture=FALSE;
- MaxMipLevel=0;
- MipMapLodBias=0;
- };
- sampler2D SamplerNs = sampler_state
- {
- Texture = <texNs>;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- MipFilter = LINEAR;
- AddressU = Wrap;
- AddressV = Wrap;
- AddressW = Wrap;
- SRGBTexture=FALSE;
- MaxMipLevel=0;
- MipMapLodBias=0;
- };
- sampler2D SamplerNs2 = sampler_state
- {
- Texture = <texNs2>;
- MinFilter = LINEAR;
- MagFilter = LINEAR;
- MipFilter = LINEAR;
- AddressU = Wrap;
- AddressV = Wrap;
- AddressW = Wrap;
- SRGBTexture=FALSE;
- MaxMipLevel=0;
- MipMapLodBias=0;
- };
- struct VS_OUTPUT_POST
- {
- float4 vpos : POSITION;
- float2 txcoord : TEXCOORD0;
- };
- struct VS_INPUT_POST
- {
- float3 pos : POSITION;
- float2 txcoord : TEXCOORD0;
- };
- ////////////////////////////////////////////////////////////////
- VS_OUTPUT_POST VS_PostProcess(VS_INPUT_POST IN)
- {
- VS_OUTPUT_POST OUT;
- float4 pos=float4(IN.pos.x,IN.pos.y,IN.pos.z,1.0);
- OUT.vpos=pos;
- OUT.txcoord.xy=IN.txcoord.xy;
- return OUT;
- }
- ////////////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////SA_DirectX/////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////
- float4 WorldPos(in float2 coord)
- {
- float d0 = tex2D(SamplerDepth, coord.xy).x;
- float4 tvec;
- tvec.xy = coord.xy*2.0-1.0;
- tvec.y = -tvec.y;
- tvec.z = d0;
- tvec.w = 1.0;
- float4 wpos;
- wpos.x = dot(tvec, MatrixInverseVPRotation[0]);
- wpos.y = dot(tvec, MatrixInverseVPRotation[1]);
- wpos.z = dot(tvec, MatrixInverseVPRotation[2]);
- wpos.w = dot(tvec, MatrixInverseVPRotation[3]);
- wpos.xyz/= wpos.w;
- return wpos;
- }
- //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- float CalculateGameTime0(in float t)
- {
- float x1 = smoothstep(0.0, 4.0, t);
- float x2 = smoothstep(4.0, 5.0, t);
- float x3 = smoothstep(5.0, 6.0, t);
- float x4 = smoothstep(6.0, 7.0, t);
- float xE = smoothstep(8.0, 11.0, t);
- float x5 = smoothstep(16.0, 17.0, t);
- float x6 = smoothstep(18.0, 19.0, t);
- float x7 = smoothstep(19.0, 20.0, t);
- float xG = smoothstep(20.0, 21.0, t);
- float xZ = smoothstep(21.0, 22.0, t);
- float x8 = smoothstep(22.0, 23.0, t);
- float x9 = smoothstep(23.0, 24.0, t);
- float3 t0 = lerp(0.0, 0.1, x1);
- t0 = lerp(t0, 0.2, x2);
- t0 = lerp(t0, 0.8, x3);
- t0 = lerp(t0, 0.9, x4);
- t0 = lerp(t0, 1.0, xE);
- t0 = lerp(t0, 1.0, x5);
- t0 = lerp(t0, 0.9, x6);
- t0 = lerp(t0, 0.5, x7);
- t0 = lerp(t0, 0.4, xG);
- t0 = lerp(t0, 0.3, xZ);
- t0 = lerp(t0, 0.2, x8);
- t0 = lerp(t0, 0.0, x9);
- return t0;
- }
- float CalculateGameTime(in float t)
- {
- float x1 = smoothstep(0.0, 4.0, t);
- float x2 = smoothstep(4.0, 5.0, t);
- float x3 = smoothstep(5.0, 6.0, t);
- float x4 = smoothstep(6.0, 7.0, t);
- float xE = smoothstep(8.0, 11.0, t);
- float x5 = smoothstep(16.0, 17.0, t);
- float x6 = smoothstep(18.0, 19.0, t);
- float x7 = smoothstep(19.0, 20.0, t);
- float xG = smoothstep(20.0, 21.0, t);
- float xZ = smoothstep(21.0, 22.0, t);
- float x8 = smoothstep(22.0, 23.0, t);
- float x9 = smoothstep(23.0, 24.0, t);
- float3 t0 = lerp(0.0, 0.1, x1);
- t0 = lerp(t0, 0.7, x2);
- t0 = lerp(t0, 1.0, x3);
- t0 = lerp(t0, 1.0, x4);
- t0 = lerp(t0, 1.0, xE);
- t0 = lerp(t0, 1.0, x5);
- t0 = lerp(t0, 0.9, x6);
- t0 = lerp(t0, 0.8, x7);
- t0 = lerp(t0, 0.6, xG);
- t0 = lerp(t0, 0.4, xZ);
- t0 = lerp(t0, 0.2, x8);
- t0 = lerp(t0, 0.0, x9);
- return t0;
- }
- float Noise1(in float3 p)
- {
- float t = (Timer.x * 5.0) * 20.0;
- p.z += 0.5 * t;
- p.xyz += 1.0 * t;
- float2 uv = (p * float2(17.2, 17.2));
- float2 c = (uv + 0.5) / 20.0;
- float r0 = tex2Dlod(SamplerNs, float4(c*0.04, 0.0, 0.0)).x;
- return r0;
- }
- float Noise2(in float3 p)
- {
- float t = (Timer.x * 20.0) * 20.0;
- p.z += 0.5 * t;
- p.xyz += 1.0 * t;
- float2 uv = (p * float2(17.2, 17.2));
- float2 c = (uv + 0.5) / 20.0;
- float r0 = tex2Dlod(SamplerNs2, float4(c*0.04, 0.0, 0.0)).x;
- return r0;
- }
- float4 GWP(in float2 c, in float d)
- {
- float4 t;
- float4 w;
- t.xy=c.xy*2.0-1.0;
- t.y=-t.y;
- t.z=d;
- t.w=1.0;
- w.x=dot(t, MatrixInverseVPRotation[0]);
- w.y=dot(t, MatrixInverseVPRotation[1]);
- w.z=dot(t, MatrixInverseVPRotation[2]);
- w.w=dot(t, MatrixInverseVPRotation[3]);
- w.xyz/=w.w;
- //w.xyz+=CameraPosition;
- return w;
- }
- float SunLight(in float2 c, in float d)
- {
- float3 v0=SunDirection.xyz;
- float3 v2=normalize(float3(-0.09, -0.94, 0.31));
- float t0 = GameTime;
- float x1 = smoothstep(0.0, 4.0, t0);
- float x2 = smoothstep(4.0, 23.0, t0);
- float x3 = smoothstep(23.0, 24.0, t0);
- float3 sv = lerp(v2, v0, x1);
- sv = lerp(sv, v0, x2);
- sv = lerp(sv, v2, x3);
- float4 WorldP = GWP(c, d);
- float c0 = 6.07;
- float3 np = normalize(WorldP.xyz);
- float f0 = 0.95 - dot(-sv, np);
- f0 = pow(f0, c0);
- float r0 = (f0*f0);
- return r0/40000.0;
- }
- float Coverage(in float v, in float d, in float c)
- {
- c = clamp(c - (1.0 - v), 0.0, 1.0 - d)/(1.0 - d);
- c = max(0.0, c * 1.1 - 0.1);
- c = c = c * c * (3.0 - 2.0 * c);
- return c;
- }
- float fcc
- <
- string UIName="Clouds - Coverage";
- string UIWidget="Spinner";
- float UIMin=0.0;
- float UIMax=0.55;
- > = {0.40};
- float4 GenerateClouds(float4 worldpos, in float3 sunlight)
- {
- float t = (Timer.x * 1000.0)*20.0;
- float3 vecm = normalize(float3(-0.09, -0.94, 0.31));
- float3 sv0=-SunDirection.xyz;
- float3 sv2=-vecm;
- float t0 = GameTime;
- float x1 = smoothstep(0.0, 4.0, t0);
- float x2 = smoothstep(4.0, 5.0, t0);
- float x3 = smoothstep(5.0, 6.0, t0);
- float x4 = smoothstep(6.0, 7.0, t0);
- float xE = smoothstep(8.0, 11.0, t0);
- float x5 = smoothstep(16.0, 17.0, t0);
- float x6 = smoothstep(18.0, 19.0, t0);
- float x7 = smoothstep(19.0, 20.0, t0);
- float xG = smoothstep(20.0, 21.0, t0);
- float xZ = smoothstep(21.0, 22.0, t0);
- float x8 = smoothstep(22.0, 23.0, t0);
- float x9 = smoothstep(23.0, 24.0, t0);
- float x10 = smoothstep(4.0, 23.0, t0);
- float x11 = smoothstep(23.0, 24.0, t0);
- float3 sv = lerp(sv2, sv0, x1);
- sv = lerp(sv, sv0, x10);
- sv = lerp(sv, sv2, x11);
- float3 wp = worldpos/1.5;
- wp.x *= 0.04;
- wp.y *= 0.10;
- wp.y -= t * 0.01;
- float3 wp1 = wp * float3(1.0, 0.5, 1.0) + float3(0.0, t * 0.01, 0.0);
- float noise = Noise2(wp * float3(1.0, 0.5, 1.0) + float3(0.0, t * 0.01, 0.0));
- wp *= 3.0;
- wp.xy -= t * 0.04;
- wp.x += 2.0;
- float3 wp2 = wp;
- noise += (2.0 - abs(Noise2(wp) * 0.8)) * 0.25;
- wp *= 10.0;
- wp.xy -= t * 0.035;
- float3 wp3 = wp;
- noise += (2.0 - abs(Noise1(wp) * 1.0)) * 0.03;
- noise /= 0.80;
- float4 wx = WeatherAndTime;
- float CovCurrent;
- float CovNext;
- if (wx.x==0,1) CovCurrent = fcc;
- if (wx.y==0,1) CovNext = fcc;
- if (wx.x==0) CovCurrent = 0.00;
- if (wx.x==2) CovCurrent = 0.00;
- if (wx.x==6) CovCurrent = 0.00;
- if (wx.x==11) CovCurrent = 0.00;
- if (wx.x==13) CovCurrent = 0.00;
- if (wx.x==17) CovCurrent = 0.00;
- if (wx.x==4) CovCurrent = 1.70;
- if (wx.x==7) CovCurrent = 1.70;
- if (wx.x==8) CovCurrent = 1.70;
- if (wx.x==9) CovCurrent = 1.70;
- if (wx.x==12) CovCurrent = 1.70;
- if (wx.x==15) CovCurrent = 1.70;
- if (wx.x==16) CovCurrent = 1.70;
- if (wx.y==0) CovNext = 0.00;
- if (wx.y==2) CovNext = 0.00;
- if (wx.y==6) CovNext = 0.00;
- if (wx.y==11) CovNext = 0.00;
- if (wx.y==13) CovNext = 0.00;
- if (wx.y==17) CovNext = 0.00;
- if (wx.y==4) CovNext = 1.70;
- if (wx.y==7) CovNext = 1.70;
- if (wx.y==8) CovNext = 1.70;
- if (wx.y==9) CovNext = 1.70;
- if (wx.y==12) CovNext = 1.70;
- if (wx.y==15) CovNext = 1.70;
- if (wx.y==16) CovNext = 1.70;
- float3 wmix0 = lerp(CovCurrent, CovNext, pow(wx.z, 0.9));
- float coverage = wmix0;
- float dn = 0.1 - 0.3 * 0.3;
- noise = Coverage(coverage, dn, noise);
- float d0 = Noise2(wp1 + sv.xyz * 0.70 / 2.3);
- d0 += (2.0 - abs(Noise2(wp2 + sv.xyz * 0.70 / 2.3) * 0.8)) * 0.25;
- d0 += (2.0 - abs(Noise1(wp3 + sv.xyz * 0.70 / 2.3) * 1.0)) * 0.03;
- d0 = Coverage(0.84, dn, d0);
- float bf = lerp(clamp(pow(noise, 0.5) * 0.5, 0.0, 1.0), 0.5, pow(sunlight, 1.0));
- d0 *= bf;
- float3 lt = lerp(float3(0.0275, 0.0353, 0.0471), 0.01, x1);
- lt = lerp(lt, float3(1.0, 0.627, 0.235)*0.6, x2);
- lt = lerp(lt, float3(1.0, 0.627, 0.235), x3);
- lt = lerp(lt, float3(1.0, 0.627, 0.235), x4);
- lt = lerp(lt, float3(1.0, 1.0, 1.0), xE);
- lt = lerp(lt, float3(1.0, 1.0, 1.0), x5);
- lt = lerp(lt, float3(1.0, 0.627, 0.235), x6);
- lt = lerp(lt, float3(1.0, 0.627, 0.235), x7);
- lt = lerp(lt, 0.5, xG);
- lt = lerp(lt, 0.3, xZ);
- lt = lerp(lt, 0.1, x8);
- lt = lerp(lt, float3(0.0275, 0.0353, 0.0471), x9);
- float3 sh = lerp(float3(0.051, 0.0784, 0.118)*0.05, float3(0.03, 0.04, 0.05)*0.2, x1);
- sh = lerp(sh, float3(0.157, 0.165, 0.216)*0.6, x2);
- sh = lerp(sh, float3(0.157, 0.165, 0.216), x3);
- sh = lerp(sh, float3(0.157, 0.165, 0.216), x4);
- sh = lerp(sh, float3(0.392, 0.392, 0.392), xE);
- sh = lerp(sh, float3(0.392, 0.392, 0.392), x5);
- sh = lerp(sh, float3(0.157, 0.165, 0.216), x6);
- sh = lerp(sh, float3(0.157, 0.165, 0.216), x7);
- sh = lerp(sh, float3(0.157, 0.165, 0.216), xG);
- sh = lerp(sh, float3(0.157, 0.165, 0.216)*0.6, xZ);
- sh = lerp(sh, float3(0.157, 0.165, 0.216)*0.4, x8);
- sh = lerp(sh, float3(0.051, 0.0784, 0.118)*0.05, x9);
- float3 fmix = lerp(0.02, 0.1, x1);
- fmix = lerp(fmix, 0.1, x2);
- fmix = lerp(fmix, 0.2, x3);
- fmix = lerp(fmix, 0.5, x4);
- fmix = lerp(fmix, 0.5, xE);
- fmix = lerp(fmix, 0.5, x5);
- fmix = lerp(fmix, 0.3, x6);
- fmix = lerp(fmix, 0.2, x7);
- fmix = lerp(fmix, 0.1, xG);
- fmix = lerp(fmix, 0.05, xZ);
- fmix = lerp(fmix, 0.03, x8);
- fmix = lerp(fmix, 0.02, x9);
- float3 fmix2 = lerp(0.01, 0.1, x1);
- fmix2 = lerp(fmix2, 0.05, x2);
- fmix2 = lerp(fmix2, 0.1, x3);
- fmix2 = lerp(fmix2, 0.2, x4);
- fmix2 = lerp(fmix2, 0.2, xE);
- fmix2 = lerp(fmix2, 0.2, x5);
- fmix2 = lerp(fmix2, 0.1, x6);
- fmix2 = lerp(fmix2, 0.08, x7);
- fmix2 = lerp(fmix2, 0.05, xG);
- fmix2 = lerp(fmix2, 0.03, xZ);
- fmix2 = lerp(fmix2, 0.02, x8);
- fmix2 = lerp(fmix2, 0.01, x9);
- float3 ColorSun = lerp(float3(0.0392, 0.0588, 0.0784)*0.2, float3(0.05, 0.04, 0.02)*0.0, x1);
- ColorSun = lerp(ColorSun, float3(0.40, 0.08, 0.0)*0.8, x2);
- ColorSun = lerp(ColorSun, float3(0.45, 0.07, 0.0), x3);
- ColorSun = lerp(ColorSun, float3(0.392, 0.118, 0.0588), x4);
- ColorSun = lerp(ColorSun, float3(0.392, 0.275, 0.118), xE);
- ColorSun = lerp(ColorSun, float3(0.392, 0.275, 0.118), x5);
- ColorSun = lerp(ColorSun, float3(0.392, 0.08, 0.0), x6);
- ColorSun = lerp(ColorSun, float3(0.392, 0.08, 0.0), x7);
- ColorSun = lerp(ColorSun, float3(0.392, 0.118, 0.0588), xG);
- ColorSun = lerp(ColorSun, float3(0.392, 0.118, 0.0588)*0.4, xZ);
- ColorSun = lerp(ColorSun, float3(0.392, 0.118, 0.0588)*0.2, x8);
- ColorSun = lerp(ColorSun, float3(0.0392, 0.0588, 0.0784)*0.2, x9);
- float3 SunCurrent;
- float3 SunNext;
- float3 m0 = float3(min(1.0, d0), min(1.0, d0), min(1.0, d0));
- float3 color = lerp((pow(sunlight, 0.5)*ColorSun*50.0)+lt, sh, m0);
- float3 colorPasm = lerp(fmix, fmix2, m0);
- if (wx.x==0,1) SunCurrent = color;
- if (wx.y==0,1) SunNext = color;
- if (wx.x==4) SunCurrent = colorPasm;
- if (wx.x==7) SunCurrent = colorPasm;
- if (wx.x==8) SunCurrent = colorPasm;
- if (wx.x==9) SunCurrent = colorPasm;
- if (wx.x==12) SunCurrent = colorPasm;
- if (wx.x==15) SunCurrent = colorPasm;
- if (wx.x==16) SunCurrent = colorPasm;
- if (wx.y==4) SunNext = colorPasm;
- if (wx.y==7) SunNext = colorPasm;
- if (wx.y==8) SunNext = colorPasm;
- if (wx.y==9) SunNext = colorPasm;
- if (wx.y==12) SunNext = colorPasm;
- if (wx.y==15) SunNext = colorPasm;
- if (wx.y==16) SunNext = colorPasm;
- float3 wmix = lerp(SunCurrent, SunNext, wx.z);
- float4 r0 = float4(wmix.rgb, (noise*noise*noise));
- return r0;
- }
- float IntersectPlane(float3 pos, float3 dir)
- {
- return -pos.z/dir.z;
- }
- ////////////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////SA_DirectX/////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////
- float4 PS_DX1(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
- {
- float t = GameTime;
- float tf = CalculateGameTime(t);
- float tf2 = CalculateGameTime0(t);
- float2 coord = IN.txcoord.xy;
- float4 r0 = tex2D(SamplerColor, coord.xy);
- float d0 = tex2D(SamplerDepth, coord.xy).x;
- float4 wpos = WorldPos(coord);
- //Sky------------------------------------------------------------------------------
- float4 w0 = wpos+CameraPosition;
- float4 cam = CameraPosition;
- float4 np0 = float4(normalize(wpos.xyz), 1.0);
- np0.xyz = normalize(w0.xyz-float3(cam.xy, 0.0));
- float3 vec = normalize(float3(0.0, 0.0, 1.0));
- float3 hv = normalize(-vec+np0);
- float np4 = (np0.z * (2.0)) + 0.40;
- np4 *= lerp(0.0, 1.0, tf2);
- float3 a2 = np4;
- float3 sc = 1.0;
- float3 sn = 1.0;
- float4 wx = WeatherAndTime;
- float3 wmix0 = lerp(sc, sn, wx.z);
- float4 worldpos = GWP(coord, d0);
- float L = worldpos.xyz;
- //Clouds---------------------------------------------------------------------------
- float d3 = pow(tex2D(SamplerDepth, coord).x, 17000.0);
- float3 sc0 = SunLight(coord, d3);
- float3 w1 = float3(1.0, 1.0, 3.33);
- float4 ns = float4(normalize(worldpos.xyz), 1.0);
- float ip = IntersectPlane(w1, ns.xyz);
- float4 r1 = r0;
- if (ip <= 1.0)
- if( 10000.0 < L || d0 == 1)
- {
- float4 c0 = GenerateClouds(float4((ns.xyz*ip*15.0), 1.0), sc0);
- c0.a = min(1.0, c0.a);
- r1.xyz = lerp(r0, c0.rgb*1.0, c0.a);
- }
- r0.xyz = lerp(r0, r1, smoothstep(0.0, 0.10, pow(ns.z, 1.66)));
- //---------------------------------------------------------------------------------
- return r0;
- }
- ////////////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////SA_DirectX/////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////
- float4 PS_Shadow(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
- {
- float4 res;
- float4 color=tex2D(SamplerColor, IN.txcoord.xy);
- float4 shadowtex=tex2D(SamplerShadow, IN.txcoord.xy);
- float depth=tex2D(SamplerDepth, IN.txcoord.xy).x;
- float4 origcolor=color;
- float4 tempvec;
- float4 worldpos;
- tempvec.xy=IN.txcoord.xy*2.0-1.0;
- tempvec.y=-tempvec.y;
- tempvec.z=depth;
- tempvec.w=1.0;
- worldpos.x=dot(tempvec, MatrixInverseVP[0]);
- worldpos.y=dot(tempvec, MatrixInverseVP[1]);
- worldpos.z=dot(tempvec, MatrixInverseVP[2]);
- worldpos.w=dot(tempvec, MatrixInverseVP[3]);
- worldpos.xyz/=worldpos.w;
- worldpos.w=1.0;
- worldpos.z=dot(worldpos, MatrixVP[2]);
- float fogdist;
- fogdist=worldpos.z;
- float fadefact=(FogParam.w - fogdist) / (FogParam.w - FogParam.z);
- fadefact=saturate(1.0-fadefact);
- //remove fog
- color.xyz=(color.xyz - FogFarColor.xyz*fadefact)/(1.00001-fadefact);
- color.xyz=max(color.xyz, 0.0);
- //remove from sides
- float4 normal=tex2D(SamplerNormal, IN.txcoord.xy);
- normal.xyz=normal.xyz*2.0-1.0;
- float4 normalpos;
- tempvec.xyz=normal.xyz;
- tempvec.x=-tempvec.x;
- tempvec.w=1.0;
- normalpos.x=dot(tempvec.xyz, MatrixInverseView[0]);
- normalpos.y=dot(tempvec.xyz, MatrixInverseView[1]);
- normalpos.z=dot(tempvec.xyz, MatrixInverseView[2]);
- normalpos.xyz=normalize(normalpos.xyz);
- float3 sunvec=SunDirection.xyz;
- float sidefact=dot(normalpos.xyz, sunvec.xyz);
- sidefact*=saturate(SunDirection.z * 6.0); //if sun below horizon, disable this
- shadowtex*=saturate(1.0-sidefact * 6.0);
- shadowtex=lerp(shadowtex, 1.0, fadefact); //reduce based on fog, guess not required becaose of defog code
- shadowtex=lerp(1.0, shadowtex, EShadowAmount); //reduce in general
- //apply shadow
- color.xyz*=shadowtex;
- //apply fog again
- color.xyz=lerp(color.xyz, FogFarColor.xyz, fadefact);
- res=color;
- //ignore sky
- if (depth>=0.999999) res=origcolor;
- res.w=1.0; //color.w;
- return res;
- }
- //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- technique PostProcess
- {
- pass P0
- {
- VertexShader = compile vs_3_0 VS_PostProcess();
- PixelShader = compile ps_3_0 PS_DX1();
- }
- }
- technique PostProcess2
- {
- pass P0
- {
- VertexShader = compile vs_3_0 VS_PostProcess();
- PixelShader = compile ps_3_0 PS_Shadow();
- ALPHATESTENABLE=FALSE;
- SEPARATEALPHABLENDENABLE=FALSE;
- AlphaBlendEnable=FALSE;
- SRGBWRITEENABLE=FALSE;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement