source: trunk/src/easymesh/shiny.lolfx @ 2232

Last change on this file since 2232 was 2232, checked in by lolbot, 8 years ago

fixed 27 files out of 2315:

  • removed 0 CR characters
  • removed 188 trailing whitespaces
  • replaced 537 tabs with spaces
File size: 6.0 KB
Line 
1
2[vert.glsl]
3#version 120
4
5attribute vec3 in_Vertex;
6attribute vec3 in_Normal;
7attribute vec4 in_Color;
8
9uniform mat4 in_ModelView;
10uniform mat4 in_View;
11uniform mat4 in_Proj;
12uniform mat3 in_NormalMat;
13
14varying vec4 pass_Vertex; /* View space */
15varying vec3 pass_TNormal;
16varying vec4 pass_Color;
17
18void main(void)
19{
20    vec4 vertex = in_ModelView * vec4(in_Vertex, 1.0);
21    vec3 tnorm = normalize(in_NormalMat * in_Normal);
22
23    pass_Vertex = vertex;
24    pass_TNormal = tnorm;
25    pass_Color = in_Color;
26
27    gl_Position = in_Proj * vertex;
28}
29
30[frag.glsl]
31#version 120
32
33#if defined GL_ES
34precision highp float;
35#endif
36
37uniform float in_Damage;
38uniform mat4 in_View;
39uniform mat4 in_Inv_View;
40
41varying vec4 pass_Vertex; /* View space */
42varying vec3 pass_TNormal;
43varying vec4 pass_Color;
44
45// FIXME: all the light parameters should be passed in the code
46//Dir Light
47vec3 in_LightDir = vec3(-0.3, -0.3, -0.7);
48
49//Point Light
50vec4 in_Light2_Pos = vec4(20.0, 10.0, 0.0, 1.0);
51float in_Light2_Radius = 20.0;
52vec3 in_Light2_diffuse = vec3(0.4, 0.4, 1.0);
53
54//Cube Light
55vec4 in_Light3_Pos = vec4(-10.0, 10.0, 5.0, 1.0);
56vec3 in_Light3_Size_Inner = vec3(3.0, 1.0, 3.0);
57vec3 in_Light3_Size_Outer = vec3(15.0, 15.0, 15.0);
58vec3 in_Light3_diffuse = vec3(0.4, 1.0, 0.4);
59
60void main(void)
61{
62    /* Material properties */
63    vec3 specular_reflect = vec3(0.8, 0.75, 0.4);
64    float specular_power = 60.0;
65
66    /* World properties */
67    float ambient_mul = 0.5;
68    vec3 ambient_color = vec3(0.0, 0.0, 0.0);
69    vec3 diffuse_color = vec3(0.4, 0.4, 0.4);
70    vec3 specular_color = vec3(1.0, 1.0, 0.6);
71
72    vec3 ambient = ambient_color;
73    vec3 specular = vec3(0.0, 0.0, 0.0);
74    vec3 diffuse = vec3(0.0, 0.0, 0.0);
75    vec3 s = vec3(0.0, 0.0, 0.0);
76    vec3 v = vec3(0.0, 0.0, 0.0);
77    vec3 r = vec3(0.0, 0.0, 0.0);
78    float sdotn = 0.0;
79    float light_radius_mod = 0.0;
80
81    //Light calculation for directional light
82    s = normalize(-in_LightDir);
83    v = normalize(-pass_Vertex.xyz);
84    r = reflect(s, pass_TNormal);
85
86    sdotn = max(dot(s, pass_TNormal), 0.0);
87    diffuse += diffuse_color * sdotn;
88    if (sdotn > 0.0)
89        specular += specular_color * specular_reflect
90                 * pow(max(dot(r, v), 0.0), specular_power);
91    //----------
92
93    //Light calculation for point light
94    vec3 tmpLightDir = (in_View * in_Light2_Pos).xyz - pass_Vertex.xyz;
95    light_radius_mod = max(0.0, 1.0 - (length(tmpLightDir) / in_Light2_Radius));
96    s = normalize(tmpLightDir);
97    v = normalize(-pass_Vertex.xyz);
98    r = reflect(-s, pass_TNormal);
99
100    sdotn = max(dot(s, pass_TNormal), 0.0);
101    diffuse += in_Light2_diffuse * min(sdotn, light_radius_mod);
102    if (sdotn > 0.0 && light_radius_mod > 0.0)
103        specular += specular_color * min(specular_reflect, light_radius_mod)
104                 * pow(max(dot(r, v), 0.0), specular_power);
105    //----------
106
107    //Light calculation for cube light
108    vec3 Local_Vertex = (in_Inv_View * pass_Vertex).xyz - (in_Light3_Pos).xyz;
109    vec3 Proj_Vertex = clamp(Local_Vertex.xyz, -in_Light3_Size_Inner, in_Light3_Size_Inner);
110    vec3 new_LightDir = Local_Vertex - Proj_Vertex;
111
112    vec3 light_radius = max(vec3(0.0,0.0,0.0), vec3(1.0,1.0,1.0) - abs(new_LightDir / in_Light3_Size_Outer));
113    light_radius_mod = min(light_radius.x, min(light_radius.y, light_radius.z));
114
115    if (length(new_LightDir) == 0.0)
116        sdotn = 1.0;
117    else
118    {
119        new_LightDir = normalize((in_View * vec4(Proj_Vertex + in_Light3_Pos.xyz,1.0)).xyz - pass_Vertex.xyz);
120        sdotn = max(dot(new_LightDir, pass_TNormal), 0.0);
121        r = reflect(-new_LightDir, pass_TNormal);
122        if (sdotn > 0.0 && light_radius_mod > 0.0)
123            specular += specular_color * min(specular_reflect, light_radius_mod)
124                     * pow(max(dot(r, v), 0.0), specular_power);
125    }
126    diffuse += in_Light3_diffuse * min(sdotn, light_radius_mod);
127    //----------
128
129    vec3 light = ambient + diffuse + specular;
130
131    vec4 real_color = in_Damage * vec4(1.2, 1.2, 1.2, 1.0)
132                    + (1.0 - in_Damage) * pass_Color;
133    gl_FragColor = real_color * vec4(light, 1.0);
134}
135
136[vert.hlsl]
137
138void main(float3 in_Vertex : POSITION,
139          float3 in_Normal : NORMAL,
140          float4 in_Color : COLOR,
141          uniform float4x4 in_ModelView,
142          uniform float4x4 in_Model,
143          uniform float4x4 in_Proj,
144          uniform float3x3 in_NormalMat,
145          out float4 pass_Vertex : TEXCOORD0,
146          out float3 pass_TNormal : TEXCOORD1,
147          out float4 pass_Color : COLOR,
148          out float4 out_Position : POSITION)
149{
150    float4 eye = mul(in_ModelView, float4(in_Vertex, 1.0));
151    float3 tnorm = normalize(mul(in_NormalMat, in_Normal));
152
153    pass_Vertex = eye;
154    pass_TNormal = tnorm;
155#ifdef _XBOX
156    pass_Color = in_Color.abgr;
157#else
158    pass_Color = in_Color;
159#endif
160
161    out_Position = mul(in_Proj, eye);
162}
163
164[frag.hlsl]
165
166void main(float4 pass_Vertex : TEXCOORD0,
167          float3 pass_TNormal : TEXCOORD1,
168          float4 pass_Color : COLOR,
169          uniform float in_Damage,
170          out float4 out_FragColor : COLOR)
171{
172    float3 in_LightDir = float3(0.3, 0.3, 0.7);
173
174    /* Material properties */
175    float3 specular_reflect = float3(0.8, 0.75, 0.4);
176    float specular_power = 60.0;
177
178    /* World properties */
179    float ambient_mul = 0.5;
180    float3 ambient_color = float3(0.25, 0.2, 0.35);
181    float3 diffuse_color = float3(1.0, 1.0, 0.6);
182    float3 specular_color = float3(1.0, 1.0, 0.6);
183
184    float3 s = normalize(in_LightDir); /* normalize(pass_Vertex - lightpos); */
185    float3 v = normalize(-pass_Vertex.xyz);
186    float3 r = reflect(-s, pass_TNormal);
187
188    float3 ambient = ambient_color;
189    float sdotn = max(dot(s, pass_TNormal), 0.0);
190    float3 diffuse = diffuse_color * sdotn;
191    float3 specular = float3(0.0, 0.0, 0.0);
192    if (sdotn > 0.0)
193        specular = specular_color * specular_reflect
194                 * pow(max(dot(r, v), 0.0), specular_power);
195    float3 light = ambient + diffuse + specular;
196
197    float4 real_color = in_Damage * float4(1.2, 1.2, 1.2, 1.0)
198                      + (1.0 - in_Damage) * pass_Color;
199    out_FragColor = real_color * float4(light, 1.0);
200}
201
Note: See TracBrowser for help on using the repository browser.