Budujemy silnik: shadery kontratakujÄ… - wynikowy kod Cg

 1: varying out float4 Out_PositionWorld : TEXCOORD2;
 2: varying out float4 Out_Light1_ShadowCoord : TEXCOORD0;
 3: varying out float3 Out_Normal : TEXCOORD1;
 4: varying out float4 Out_Position : POSITION;
 5: 
 6: uniform float4x4 Light1_MatrixShadow;
 7: uniform float4x4 Scene_MatrixMVP;
 8: uniform float4x4 Scene_MatrixObjectToWorld;
 9: 
10: varying float3 Stream_Normal : NORMAL;
11: varying float3 Stream_Position : POSITION;
12: 
13: void vertex_shader()
14: {
15: Out_PositionWorld = mul(Scene_MatrixObjectToWorld, float4(Stream_Position, 1));
16: float4 core = Out_PositionWorld;
17: Out_Light1_ShadowCoord = mul(Light1_MatrixShadow, core);
18: Out_Normal = Stream_Normal;
19: float4 core1 = Out_PositionWorld;
20: core1 = mul(Scene_MatrixMVP, core1);
21: Out_Position = core1;
22: }
23: 

 1: uniform float3 Light0_Direction;
 2: uniform float3 Light1_PositionWorld;
 3: uniform sampler2D Light1_ShadowMap;
 4: uniform float Light1_Strength;
 5: uniform float4 Material_MaterialColor;
 6: 
 7: varying float4 Light1_ShadowCoord : TEXCOORD0;
 8: varying float3 Normal : TEXCOORD1;
 9: varying float4 PositionWorld : TEXCOORD2;
10: 
11: out varying float4 OutColor0 : COLOR0;
12: 
13: void pixel_shader()
14: {
15: float4 color = float4(0,0,0,0);
16: float4 subcolor1 = float4(0,0,0,0);
17: float4 diffuse_color1 = float4(0,0,0,0);
18: diffuse_color1 = Material_MaterialColor;
19: float3 normal2 = Normal;
20: float3 lightdirection = Light0_Direction;
21: float dotproduct2 = dot(normal2, lightdirection);
22: diffuse_color1 *= dotproduct2;
23: float4 diffuse = diffuse_color1;
24: float4 specular1 = float4(0,0,0,0);
25: subcolor1 += diffuse + specular1;
26: color += subcolor1;
27: float4 subcolor = float4(0,0,0,0);
28: float4 xyz = float4(0,0,0,0);
29: xyz = tex2D(Light1_ShadowMap, Light1_ShadowCoord.xy);
30: xyz /= Light1_ShadowCoord.z;
31: float shadow = xyz.r;
32: float3 distance = Light1_PositionWorld - PositionWorld.xyz;
33: float distancelen = dot(distance, distance);
34: float att = 1;
35: att -= distancelen / Light1_Strength;
36: float attenuation = att;
37: float4 diffuse_color = float4(0,0,0,0);
38: diffuse_color = Material_MaterialColor;
39: float3 normal3 = Normal;
40: float3 lightdirection1 = normalize(Light1_PositionWorld - PositionWorld.xyz);
41: float dotproduct3 = dot(normal3, lightdirection1);
42: diffuse_color *= dotproduct3;
43: float4 diffuse1 = diffuse_color;
44: float4 specular = float4(0,0,0,0);
45: subcolor += diffuse1 + specular;
46: subcolor *= attenuation;
47: subcolor *= shadow;
48: color += subcolor;
49: OutColor0 = color;
50: }
51: 

Comments:

Leave comment: