1 | //#define VARIANCE_SHADOW_MAPPING
|
---|
2 |
|
---|
3 | #define MAX_LIGHT 2
|
---|
4 |
|
---|
5 | #include "MoriaSceneillum.hlsl"
|
---|
6 |
|
---|
7 | uniform sampler2D colorTexture : register(s0);
|
---|
8 | uniform sampler2D normalMap : register(s1);
|
---|
9 | uniform samplerCUBE ShadowMap1Point : register(s2);
|
---|
10 | uniform samplerCUBE ShadowMap2Point : register(s3);
|
---|
11 | uniform samplerCUBE colorEnvMap : register(s4);
|
---|
12 | uniform samplerCUBE hiColorEnvMap : register(s5);
|
---|
13 |
|
---|
14 | uniform float4x4 WorldViewProj;
|
---|
15 | uniform float4x4 World;
|
---|
16 | uniform float4x4 WorldI;
|
---|
17 |
|
---|
18 | uniform float3 wCamPos;
|
---|
19 |
|
---|
20 | uniform float4 wLightPos1;
|
---|
21 | uniform float4 wLightPos2;
|
---|
22 | uniform float4 lightRange1;
|
---|
23 | uniform float4 lightRange2;
|
---|
24 | uniform float lightPower1;
|
---|
25 | uniform float lightPower2;
|
---|
26 | uniform float4 lightColor1;
|
---|
27 | float4 lightColor2 = 0;
|
---|
28 |
|
---|
29 | uniform float4x4 LightView1;
|
---|
30 | uniform float4x4 LightView2;
|
---|
31 | uniform float lightFarPlane1;
|
---|
32 | uniform float lightFarPlane2;
|
---|
33 |
|
---|
34 | uniform float specularity;
|
---|
35 | uniform float4 specularColor;
|
---|
36 | uniform float4 diffColor;
|
---|
37 |
|
---|
38 |
|
---|
39 | struct CHARACTER_VSOUT
|
---|
40 | {
|
---|
41 | float4 hPos : POSITION;
|
---|
42 | float2 texCoord : TEXCOORD0;
|
---|
43 | float3 wView : TEXCOORD1;
|
---|
44 | float3 wTangent : TEXCOORD2;
|
---|
45 | float3 wBinormal : TEXCOORD3;
|
---|
46 | float3 wNormal : TEXCOORD4;
|
---|
47 | float3 wPos : TEXCOORD5;
|
---|
48 | };
|
---|
49 |
|
---|
50 | CHARACTER_VSOUT CharacterBase_VS(float4 position :POSITION,
|
---|
51 | float3 normal :NORMAL,
|
---|
52 | float2 texCoord : TEXCOORD0,
|
---|
53 | float3 tangent : TEXCOORD1)
|
---|
54 | {
|
---|
55 | CHARACTER_VSOUT OUT = (CHARACTER_VSOUT) 0;
|
---|
56 |
|
---|
57 | OUT.texCoord = texCoord;
|
---|
58 |
|
---|
59 | OUT.hPos = mul(WorldViewProj, position);
|
---|
60 | OUT.wPos = mul(World, position);
|
---|
61 |
|
---|
62 | OUT.wView = wCamPos - OUT.wPos;
|
---|
63 |
|
---|
64 | OUT.wTangent = normalize(mul(float4(tangent, 1),WorldI)).xyz;
|
---|
65 | OUT.wNormal = normalize(mul(float4(normal, 1),WorldI)).xyz;
|
---|
66 | OUT.wBinormal = cross(OUT.wTangent, OUT.wNormal).xyz;
|
---|
67 |
|
---|
68 | return OUT;
|
---|
69 | }
|
---|
70 |
|
---|
71 | float4 CharacterBase_PS(CHARACTER_VSOUT IN, uniform float3 lastCenter, uniform float type):COLOR0
|
---|
72 | {
|
---|
73 | float4 Color = 0;
|
---|
74 | float3 N = IN.wNormal;
|
---|
75 | if(dot(IN.wBinormal, IN.wBinormal) != 0 )
|
---|
76 | N = NormalMap(IN.wTangent, IN.wBinormal, IN.wNormal, IN.texCoord, normalMap);
|
---|
77 | // N = ParallaxMap(IN.wTangent, IN.wBinormal, IN.wNormal, IN.wView, IN.texCoord, normalMap);
|
---|
78 |
|
---|
79 | N = normalize(N);
|
---|
80 |
|
---|
81 | float dist = length(IN.wView);
|
---|
82 | float3 V = IN.wView / dist;
|
---|
83 | // read textures
|
---|
84 | float4 diffuseColor = tex2D(colorTexture, IN.texCoord);
|
---|
85 |
|
---|
86 | //----------------------------------------------------------------------------------------------------------------
|
---|
87 | //light1
|
---|
88 | //light dir
|
---|
89 | float3 L;
|
---|
90 | float4 col;
|
---|
91 | float3 lightCPos;
|
---|
92 | float shadow;
|
---|
93 |
|
---|
94 | if( dot(lightRange1, lightRange1) != 0)
|
---|
95 | {
|
---|
96 | L = wLightPos1.xyz - IN.wPos * wLightPos1.w;
|
---|
97 | //illumination
|
---|
98 | col = Illumination(N, L, V, lightColor1 * lightPower1, lightRange1, diffuseColor*diffColor, specularity, specularColor);
|
---|
99 | //shadowing
|
---|
100 | lightCPos = mul(LightView1, float4(IN.wPos, 1)).xyz;
|
---|
101 | shadow = shadowPoint(ShadowMap1Point, lightCPos, lightFarPlane1);
|
---|
102 | //shadow = 1;
|
---|
103 | Color += col * shadow;
|
---|
104 |
|
---|
105 | //Color = col;
|
---|
106 | }
|
---|
107 |
|
---|
108 | //----------------------------------------------------------------------------------------------------------------
|
---|
109 | //light2
|
---|
110 | if( dot(lightRange2, lightRange2) != 0 )
|
---|
111 | {
|
---|
112 | //light dir
|
---|
113 | L = wLightPos2.xyz - IN.wPos * wLightPos2.w;
|
---|
114 | //illumination
|
---|
115 | col = Illumination(N, L, V, lightColor2 * lightPower2, lightRange2, diffuseColor*diffColor, specularity, specularColor);
|
---|
116 | //shadowing
|
---|
117 | lightCPos = mul(LightView2, float4(IN.wPos, 1)).xyz;
|
---|
118 | shadow = shadowPoint(ShadowMap2Point, lightCPos, lightFarPlane2);
|
---|
119 | Color += col * shadow;
|
---|
120 | }
|
---|
121 |
|
---|
122 | float4 indirect = 0;
|
---|
123 | float reflectivity = 0.5;
|
---|
124 |
|
---|
125 | if(type == 0)
|
---|
126 | {
|
---|
127 | indirect = diffuseColor * diffuseIndirect(colorEnvMap, colorEnvMap, N, IN.wPos - lastCenter, V);
|
---|
128 | Color = Color + indirect;
|
---|
129 | }
|
---|
130 | else if(type == 1)
|
---|
131 | {
|
---|
132 | indirect = readCubeMap(hiColorEnvMap, reflect(-V,N));
|
---|
133 | Color = Color * (1-reflectivity) + reflectivity * /*diffuseColor **/ indirect;
|
---|
134 | }
|
---|
135 | else if(type == 2)
|
---|
136 | {
|
---|
137 | indirect = glossyIndirect(colorEnvMap, colorEnvMap, N, IN.wPos - lastCenter, -V);
|
---|
138 | Color = Color * (1-reflectivity) + reflectivity * /*diffuseColor **/ indirect;
|
---|
139 | }
|
---|
140 |
|
---|
141 |
|
---|
142 | Color.a = dist;
|
---|
143 |
|
---|
144 | //return Color * 0.000000001 + N.xyzz;
|
---|
145 | //return dot(N,L);
|
---|
146 | return Color;
|
---|
147 | }
|
---|