1 | //#define VARIANCE_SHADOW_MAPPING
|
---|
2 |
|
---|
3 | #define MAX_LIGHT 2
|
---|
4 | #define MAX_CAU_CASTER 2
|
---|
5 | #define SPOT_ANGLE 2.093
|
---|
6 | #define SPOT_FALLOFF 1
|
---|
7 | #define SHADOW_COLOR float4(0.3,0.3,0.3,1.0)
|
---|
8 | #define SHADOW_BIAS_POINT 0.0001
|
---|
9 | #define SHADOW_EPSILON_POINT 0.0001
|
---|
10 |
|
---|
11 | #include "illum.hlsl"
|
---|
12 |
|
---|
13 | uniform sampler2D tileTexture : register(s0);
|
---|
14 | uniform sampler2D detailTexture : register(s1);
|
---|
15 | uniform sampler2D bumpMap : register(s2);
|
---|
16 | uniform sampler2D PathMap : register(s3);
|
---|
17 | uniform sampler2D WeightIndexMap : register(s4);
|
---|
18 | uniform sampler2D WeightMap : register(s5);
|
---|
19 | uniform samplerCUBE ShadowMap1Point : register(s6);
|
---|
20 | uniform samplerCUBE ShadowMap2Point : register(s7);
|
---|
21 |
|
---|
22 | uniform float4x4 WorldViewProj;
|
---|
23 | uniform float4x4 World;
|
---|
24 | uniform float4x4 WorldI;
|
---|
25 |
|
---|
26 | uniform float3 wCamPos;
|
---|
27 |
|
---|
28 | uniform float4 wLightPos1;
|
---|
29 | uniform float4 wLightPos2;
|
---|
30 | uniform float4 lightRange1;
|
---|
31 | uniform float4 lightRange2;
|
---|
32 | uniform float lightPower1;
|
---|
33 | uniform float lightPower2;
|
---|
34 | uniform float4 lightColor1;
|
---|
35 | uniform float4 lightColor2;
|
---|
36 |
|
---|
37 | uniform float4x4 LightView1;
|
---|
38 | uniform float4x4 LightView2;
|
---|
39 | uniform float lightFarPlane1;
|
---|
40 | uniform float lightFarPlane2;
|
---|
41 |
|
---|
42 | uniform float specularity;
|
---|
43 |
|
---|
44 |
|
---|
45 | struct MORIA_HALL_BASE_VSOUT
|
---|
46 | {
|
---|
47 | float4 hPos : POSITION;
|
---|
48 | float4 texCoord : TEXCOORD0;
|
---|
49 | float4 texCoord2 : TEXCOORD1;
|
---|
50 | float3 wView : TEXCOORD2;
|
---|
51 | float3 wTangent : TEXCOORD3;
|
---|
52 | float3 wBinormal : TEXCOORD4;
|
---|
53 | float3 wNormal : TEXCOORD5;
|
---|
54 | float3 wPos : TEXCOORD6;
|
---|
55 | };
|
---|
56 |
|
---|
57 | MORIA_HALL_BASE_VSOUT MoriaHallBase_VS(float4 position :POSITION,
|
---|
58 | float3 normal :NORMAL,
|
---|
59 | float2 texCoord1 : TEXCOORD0,
|
---|
60 | float2 texCoord2 : TEXCOORD1,
|
---|
61 | float2 atlasTex : TEXCOORD2,
|
---|
62 | float3 tangent : TEXCOORD3,
|
---|
63 | uniform float normalCoord)
|
---|
64 | {
|
---|
65 | MORIA_HALL_BASE_VSOUT OUT = (MORIA_HALL_BASE_VSOUT) 0;
|
---|
66 |
|
---|
67 | OUT.texCoord = float4(texCoord1.xy, texCoord2.xy);
|
---|
68 | if(normalCoord == 0)
|
---|
69 | OUT.texCoord2.xy = texCoord1;
|
---|
70 | else
|
---|
71 | OUT.texCoord2.xy = texCoord2;
|
---|
72 |
|
---|
73 | OUT.texCoord2.zw = atlasTex;
|
---|
74 |
|
---|
75 | OUT.hPos = mul(WorldViewProj, position);
|
---|
76 | OUT.wPos = mul(World, position);
|
---|
77 |
|
---|
78 | OUT.wView = wCamPos - OUT.wPos;
|
---|
79 |
|
---|
80 | OUT.wTangent = normalize(mul(float4(tangent, 1),WorldI)).xyz;
|
---|
81 | OUT.wNormal = normalize(mul(float4(normal, 1),WorldI)).xyz;
|
---|
82 | OUT.wBinormal = cross(OUT.wTangent, OUT.wNormal).xyz;
|
---|
83 |
|
---|
84 | return OUT;
|
---|
85 | }
|
---|
86 |
|
---|
87 | float4 MoriaHallBase_PS(MORIA_HALL_BASE_VSOUT IN):COLOR0
|
---|
88 | {
|
---|
89 | float4 Color = 0;
|
---|
90 | float3 N = NormalMap(IN.wTangent, IN.wBinormal, IN.wNormal, IN.texCoord2.xy, bumpMap);
|
---|
91 | float3 V = normalize(IN.wView);
|
---|
92 | // read textures
|
---|
93 | float4 diffuseColor = tex2D(tileTexture, IN.texCoord.zw) * tex2D(detailTexture, IN.texCoord.xy);
|
---|
94 |
|
---|
95 | //----------------------------------------------------------------------------------------------------------------
|
---|
96 | //light1
|
---|
97 | //light dir
|
---|
98 | float3 L = wLightPos1.xyz - IN.wPos * wLightPos1.w;
|
---|
99 | //illumination
|
---|
100 | float4 col;
|
---|
101 | col = Illumination(N, L, V, lightColor1 * lightPower1, lightRange1, diffuseColor, specularity);
|
---|
102 | //shadowing
|
---|
103 | float3 lightCPos = mul(LightView1, float4(IN.wPos, 1)).xyz;
|
---|
104 | float shadow = shadowPoint(ShadowMap1Point, lightCPos, lightFarPlane1);
|
---|
105 | Color += col * shadow;
|
---|
106 |
|
---|
107 | //----------------------------------------------------------------------------------------------------------------
|
---|
108 | //light2
|
---|
109 | //light dir
|
---|
110 | L = wLightPos2.xyz - IN.wPos * wLightPos2.w;
|
---|
111 | //illumination
|
---|
112 | col = Illumination(N, L, V, lightColor2 * lightPower2, lightRange2, diffuseColor, specularity);
|
---|
113 | //shadowing
|
---|
114 | lightCPos = mul(LightView2, float4(IN.wPos, 1)).xyz;
|
---|
115 | shadow = shadowPoint(ShadowMap2Point, lightCPos, lightFarPlane2);
|
---|
116 | Color += col * shadow;
|
---|
117 |
|
---|
118 | //do Path Map to gather indirect illumination
|
---|
119 |
|
---|
120 | float4 indirect = PathMapIndirect(PathMap, WeightIndexMap, WeightMap, IN.texCoord2.zw) * 1.2;
|
---|
121 | indirect *= diffuseColor;
|
---|
122 | Color = Color + indirect;
|
---|
123 |
|
---|
124 | //gather caustics for all casters
|
---|
125 | //return diffuseColor;
|
---|
126 | return Color;
|
---|
127 | } |
---|