[2474] | 1 | //#define VARIANCE_SHADOW_MAPPING
|
---|
| 2 | #define MAX_LIGHT 2
|
---|
| 3 | #define MAX_CAU_CASTER 2
|
---|
| 4 | #define HIGH_QUALITY
|
---|
| 5 |
|
---|
| 6 | struct Shaded_OUT
|
---|
| 7 | {
|
---|
| 8 | float4 vPos : POSITION;
|
---|
| 9 | float4 wNormal : TEXCOORD0;
|
---|
| 10 | float4 wPos : TEXCOORD1;
|
---|
| 11 | };
|
---|
| 12 |
|
---|
| 13 | Shaded_OUT MorphedSphere_VS(float4 position : POSITION,
|
---|
| 14 | float4 normal : NORMAL,
|
---|
| 15 | float2 texCoord : TEXCOORD0,
|
---|
| 16 | uniform float4x4 WorldViewProj,
|
---|
| 17 | uniform float4x4 World,
|
---|
| 18 | uniform float4x4 WorldInv,
|
---|
| 19 | uniform float t)
|
---|
| 20 | {
|
---|
| 21 | Shaded_OUT OUT;
|
---|
| 22 |
|
---|
| 23 | float dist = sin(t + position.x * position.y * 5.0 + position.z) * 0.3;
|
---|
| 24 | float3 dist2 = sin(t + position.x * position.y * 5.0 + position.z + float3(0.005,0.005,0.001)) * 0.3;
|
---|
| 25 |
|
---|
| 26 | float3 pos2 = (position + float3(0.001,0.001,0.001));
|
---|
| 27 | pos2 += normalize(pos2) * dist;
|
---|
| 28 | position.xyz += normalize(position.xyz) * dist;
|
---|
| 29 |
|
---|
| 30 | normal.xyz = cross(cross(normalize(pos2 - position.xyz), normal.xyz), normalize(pos2 - position.xyz));
|
---|
| 31 | if(length(normal.xyz < 0.01))
|
---|
| 32 | normal = position;
|
---|
| 33 |
|
---|
| 34 | OUT.vPos = mul(WorldViewProj, position);
|
---|
| 35 |
|
---|
| 36 | OUT.wPos = mul(World, position);
|
---|
| 37 | OUT.wNormal = mul(normal, WorldInv);
|
---|
| 38 | return OUT;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | struct CPos_OUT
|
---|
| 42 | {
|
---|
| 43 | float4 VPos : POSITION;
|
---|
| 44 | float4 CPos : TEXCOORD0;
|
---|
| 45 | };
|
---|
| 46 |
|
---|
| 47 | #ifdef HIGH_QUALITY
|
---|
| 48 |
|
---|
| 49 | CPos_OUT MorphedSphereSM_VS(float4 position : POSITION,
|
---|
| 50 | uniform float4x4 WorldViewProj,
|
---|
| 51 | uniform float4x4 WorldView,
|
---|
| 52 | uniform float t)
|
---|
| 53 | {
|
---|
| 54 | CPos_OUT OUT;
|
---|
| 55 | float dist = sin(t + position.x * position.y * 5.0 + position.z) * 0.3;
|
---|
| 56 | position.xyz += normalize(position.xyz) * dist;
|
---|
| 57 |
|
---|
| 58 | OUT.VPos = mul(WorldViewProj, position);
|
---|
| 59 | OUT.CPos = mul(WorldView, position);
|
---|
| 60 | return OUT;
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | float4 MorphedSphereSM_PS(CPos_OUT IN,
|
---|
| 64 | uniform float farPlane) : COLOR
|
---|
| 65 | {
|
---|
| 66 | float dist = length(IN.CPos.xyz) / farPlane;
|
---|
| 67 | return float4(dist, dist * dist, 1, dist);
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | #else
|
---|
| 71 |
|
---|
| 72 | struct VPos_OUT
|
---|
| 73 | {
|
---|
| 74 | float4 VPos : POSITION;
|
---|
| 75 | float4 VPosition : TEXCOORD0;
|
---|
| 76 | };
|
---|
| 77 |
|
---|
| 78 | VPos_OUT MorphedSphereSM_VS(float4 position : POSITION,
|
---|
| 79 | uniform float4x4 WorldViewProj,
|
---|
| 80 | uniform float t)
|
---|
| 81 | {
|
---|
| 82 | VPos_OUT OUT;
|
---|
| 83 | float dist = sin(t + position.x * position.y * 5.0 + position.z) * 0.3;
|
---|
| 84 | position.xyz += normalize(position.xyz) * dist;
|
---|
| 85 | OUT.VPos = OUT.VPosition = mul(WorldViewProj, position);
|
---|
| 86 | return OUT;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | float4 MorphedSphereSM_PS(VPos_OUT IN) : COLOR
|
---|
| 90 | {
|
---|
| 91 | float4 pos = IN.VPosition / IN.VPosition.w;
|
---|
| 92 | return float4(pos.z, 0, 0, 1);
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | #endif
|
---|
| 96 |
|
---|
| 97 | CPos_OUT MorphedSphereCDepth_VS(float4 position : POSITION,
|
---|
| 98 | uniform float4x4 WorldViewProj,
|
---|
| 99 | uniform float4x4 WorldView,
|
---|
| 100 | uniform float t)
|
---|
| 101 | {
|
---|
| 102 | CPos_OUT OUT;
|
---|
| 103 | float dist = sin(t + position.x * position.y * 5.0 + position.z) * 0.3;
|
---|
| 104 | position.xyz += normalize(position.xyz) * dist;
|
---|
| 105 | OUT.VPos = mul(WorldViewProj, position);
|
---|
| 106 | OUT.CPos = mul(WorldView, position);
|
---|
| 107 | return OUT;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | #include "stationIllum.hlsl"
|
---|
| 111 |
|
---|
| 112 | uniform sampler2D colorTexture : register(s0);
|
---|
| 113 | uniform sampler2D obscuranceTexture : register(s1);
|
---|
| 114 | uniform sampler2D PathMap : register(s2);
|
---|
| 115 | uniform sampler2D WeightIndexMap : register(s3);
|
---|
| 116 | uniform sampler2D WeightMap : register(s4);
|
---|
| 117 | uniform samplerCUBE ShadowMap1Point : register(s5);
|
---|
| 118 | uniform samplerCUBE ShadowMap2Point : register(s6);
|
---|
| 119 | uniform sampler2D ShadowMap1 : register(s5);
|
---|
| 120 | uniform sampler2D ShadowMap2 : register(s6);
|
---|
| 121 | uniform samplerCUBE CausticCubeMap : register(s7);
|
---|
| 122 | uniform samplerCUBE CausticCasterDepthMap : register(s8);
|
---|
| 123 |
|
---|
| 124 | uniform float4x4 WorldViewProj;
|
---|
| 125 | uniform float4x4 World;
|
---|
| 126 | uniform float4x4 WorldI;
|
---|
| 127 |
|
---|
| 128 | uniform float3 wCamPos;
|
---|
| 129 |
|
---|
| 130 | uniform float4 wLightPos1;
|
---|
| 131 | uniform float4 wLightPos2;
|
---|
| 132 | uniform float4 lightRange1;
|
---|
| 133 | uniform float4 lightRange2;
|
---|
| 134 | uniform float lightPower1;
|
---|
| 135 | uniform float lightPower2;
|
---|
| 136 | uniform float4 lightColor1;
|
---|
| 137 | uniform float4 lightColor2;
|
---|
| 138 | uniform float3 wLightDir1;
|
---|
| 139 | uniform float3 wLightDir2;
|
---|
| 140 |
|
---|
| 141 | uniform float4x4 LightViewProj1;
|
---|
| 142 | uniform float4x4 LightViewProj2;
|
---|
| 143 | uniform float4x4 LightView1;
|
---|
| 144 | uniform float4x4 LightView2;
|
---|
| 145 | uniform float lightFarPlane1;
|
---|
| 146 | uniform float lightFarPlane2;
|
---|
| 147 |
|
---|
| 148 | uniform float specularity;
|
---|
| 149 | uniform float4 specularColor;
|
---|
| 150 |
|
---|
| 151 | uniform float causticReceiver;
|
---|
| 152 | uniform float3 causticCasterCenter1;
|
---|
| 153 | uniform float causticAttenuationRange1;
|
---|
| 154 |
|
---|
| 155 | struct STATION_BASE_VSOUT
|
---|
| 156 | {
|
---|
| 157 | float4 hPos : POSITION;
|
---|
| 158 | float2 texCoord : TEXCOORD0;
|
---|
| 159 | float3 wView : TEXCOORD1;
|
---|
| 160 | float3 wNormal : TEXCOORD2;
|
---|
| 161 | float3 wPos : TEXCOORD3;
|
---|
| 162 | float4 lightVPos1 : TEXCOORD4;
|
---|
| 163 | float4 lightVPos2 : TEXCOORD5;
|
---|
| 164 | float3 lightCPos1 : TEXCOORD6;
|
---|
| 165 | float3 lightCPos2 : TEXCOORD7;
|
---|
| 166 | };
|
---|
| 167 |
|
---|
| 168 | STATION_BASE_VSOUT StationBase_VS(float4 position :POSITION,
|
---|
| 169 | float3 normal :NORMAL,
|
---|
| 170 | float2 texCoord : TEXCOORD0 )
|
---|
| 171 | {
|
---|
| 172 | STATION_BASE_VSOUT OUT = (STATION_BASE_VSOUT) 0;
|
---|
| 173 |
|
---|
| 174 | OUT.texCoord = texCoord;
|
---|
| 175 |
|
---|
| 176 | OUT.hPos = mul(WorldViewProj, position);
|
---|
| 177 | OUT.wPos = mul(World, position);
|
---|
| 178 |
|
---|
| 179 | OUT.wView = wCamPos - OUT.wPos;
|
---|
| 180 |
|
---|
| 181 | OUT.wNormal = normalize(mul(float4(normal, 1),WorldI)).xyz;
|
---|
| 182 |
|
---|
| 183 | OUT.lightVPos1 = mul(LightViewProj1, float4(OUT.wPos,1));
|
---|
| 184 | OUT.lightVPos2 = mul(LightViewProj2, float4(OUT.wPos,1));
|
---|
| 185 |
|
---|
| 186 | #ifdef HIGH_QUALITY
|
---|
| 187 | OUT.lightCPos1 = mul(LightView1, float4(OUT.wPos,1)).xyz;
|
---|
| 188 | OUT.lightCPos2 = mul(LightView2, float4(OUT.wPos,1)).xyz;
|
---|
| 189 | #endif
|
---|
| 190 |
|
---|
| 191 | return OUT;
|
---|
| 192 | }
|
---|
| 193 |
|
---|
| 194 | float4 StationBase_PS(STATION_BASE_VSOUT IN):COLOR0
|
---|
| 195 | {
|
---|
| 196 | float4 Color = 0;
|
---|
| 197 | float3 N = normalize(IN.wNormal);
|
---|
| 198 | float dist = length(IN.wView);
|
---|
| 199 | float3 V = IN.wView / dist;
|
---|
| 200 | // read textures
|
---|
| 201 | float4 diffuseColor = tex2D(colorTexture, IN.texCoord);
|
---|
| 202 | float4 obscurancescolor = tex2D(obscuranceTexture, IN.texCoord);
|
---|
[2507] | 203 | //float4 combinedColor = diffuseColor * obscurancescolor;
|
---|
| 204 | float4 combinedColor = diffuseColor;
|
---|
[2474] | 205 |
|
---|
| 206 | //----------------------------------------------------------------------------------------------------------------
|
---|
| 207 | //light1
|
---|
| 208 | //light dir
|
---|
| 209 | float3 L;
|
---|
| 210 | float4 col;
|
---|
| 211 | float3 lightCPos = 0;
|
---|
| 212 | float4 lightVPos = 0;
|
---|
| 213 | float shadow;
|
---|
| 214 |
|
---|
| 215 | //if( dot(lightRange1, lightRange1) != 0)
|
---|
| 216 | {
|
---|
| 217 | L = wLightPos1.xyz - IN.wPos;
|
---|
| 218 | //illumination
|
---|
| 219 | col = Illumination(N, L, V, lightColor1 * lightPower1, lightRange1, normalize(wLightDir1), combinedColor, specularity, specularColor);
|
---|
| 220 | lightVPos = IN.lightVPos1;
|
---|
| 221 | lightCPos = IN.lightCPos1;
|
---|
| 222 | shadow = shadowMap(ShadowMap1, lightVPos, lightCPos, lightFarPlane1);
|
---|
| 223 |
|
---|
| 224 | Color += col * shadow;
|
---|
| 225 | }
|
---|
| 226 |
|
---|
| 227 | //----------------------------------------------------------------------------------------------------------------
|
---|
| 228 | //light2
|
---|
| 229 | if( dot(lightRange2, lightRange2) != 0 )
|
---|
| 230 | {
|
---|
| 231 | //light dir
|
---|
| 232 | L = wLightPos2.xyz - IN.wPos;
|
---|
| 233 | //illumination
|
---|
| 234 | col = Illumination(N, L, V, lightColor2 * lightPower2, lightRange2, normalize(wLightDir2), combinedColor, specularity, specularColor);
|
---|
| 235 |
|
---|
| 236 | lightVPos = IN.lightVPos2;
|
---|
| 237 | lightCPos = IN.lightCPos2;
|
---|
| 238 | shadow = shadowMap(ShadowMap2, lightVPos, lightCPos, lightFarPlane2);
|
---|
| 239 | Color += col * shadow;
|
---|
| 240 | }
|
---|
| 241 |
|
---|
| 242 | //do Path Map to gather indirect illumination
|
---|
| 243 |
|
---|
| 244 | float4 indirect = PathMapIndirect(PathMap, WeightIndexMap, WeightMap, IN.texCoord);
|
---|
| 245 | indirect *= diffuseColor;
|
---|
[2507] | 246 | Color = Color + indirect * 1.5;
|
---|
| 247 | //Color = Color + diffuseColor * 0.1;
|
---|
[2474] | 248 |
|
---|
| 249 | if(causticReceiver)
|
---|
| 250 | {
|
---|
| 251 | //Color *= 0.00000000001;
|
---|
[2527] | 252 | Color.rgb += diffuseColor.rgb * Caustics(CausticCubeMap, CausticCasterDepthMap, IN.wPos - causticCasterCenter1, causticAttenuationRange1);
|
---|
[2474] | 253 | }
|
---|
| 254 | //Color.a = dist;
|
---|
| 255 | return Color;
|
---|
| 256 | } |
---|