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

Last change on this file since 1690 was 1690, checked in by sam, 8 years ago

gpu: try to patch some simple GLSL shaders on the fly so that they
work on OpenGL ES contexts.

File size: 3.2 KB
Line 
1
2-- GLSL.Vert --
3#version 120
4
5attribute vec3 in_Vertex;
6attribute vec3 in_Normal;
7attribute vec4 in_Color;
8
9uniform mat4 in_ModelView;
10uniform mat4 in_Proj;
11uniform mat3 in_NormalMat;
12// FIXME: the light direction should be passed in the code
13vec3 in_LightDir = vec3(0.3, 0.3, 0.7);
14uniform float in_Damage;
15
16varying vec4 pass_Color;
17
18void main(void)
19{
20    /* Material properties */
21    vec3 specular_reflect = vec3(0.8, 0.75, 0.4);
22    float specular_power = 60.0;
23
24    /* World properties */
25    float ambient_mul = 0.5;
26    vec3 ambient_color = vec3(0.25, 0.2, 0.35);
27    vec3 diffuse_color = vec3(1.0, 1.0, 0.6);
28    vec3 specular_color = vec3(1.0, 1.0, 0.6);
29
30    vec3 tnorm = normalize(in_NormalMat * in_Normal);
31    vec4 eye = in_ModelView * vec4(in_Vertex, 1.0);
32
33    vec3 s = in_LightDir; /* normalize(eye - lightpos); */
34    vec3 v = normalize(-eye.xyz);
35    vec3 r = reflect(-s, tnorm);
36
37    vec3 ambient = ambient_color;
38    float sdotn = max(dot(s, tnorm), 0.0);
39    vec3 diffuse = diffuse_color * sdotn;
40    vec3 specular = vec3(0.0, 0.0, 0.0);
41    if (sdotn > 0.0)
42        specular = specular_color * specular_reflect
43                 * pow(max(dot(r, v), 0.0), specular_power);
44    vec3 light = ambient + diffuse + specular;
45
46    vec4 real_color = in_Damage * vec4(1.2, 1.2, 1.2, 1.0)
47                    + (1.0 - in_Damage) * in_Color;
48    pass_Color = real_color * vec4(light, 1.0);
49    gl_Position = in_Proj * eye;
50}
51
52-- GLSL.Frag --
53#version 120
54
55#if defined GL_ES
56precision highp float;
57#endif
58varying vec4 pass_Color;
59
60void main(void) {
61    gl_FragColor = pass_Color;
62}
63
64-- HLSL.Vert --
65
66void main(float3 in_Vertex : POSITION,
67          float3 in_Normal : NORMAL,
68          float4 in_Color : COLOR,
69          uniform float4x4 in_ModelView,
70          uniform float4x4 in_Proj,
71          uniform float3x3 in_NormalMat,
72          uniform float in_Damage,
73          out float4 out_Position : POSITION,
74          out float4 pass_Color : COLOR)
75{
76    float3 in_LightDir = normalize(float3(0.3, 0.3, 0.7));
77
78    float3 specular_reflect = float3(0.8, 0.75, 0.4);
79    float specular_power = 60.0;
80    float ambient_mul = 0.5;
81    float3 ambient_color = float3(0.25, 0.2, 0.35);
82    float3 diffuse_color = float3(1.0, 1.0, 0.6);
83    float3 specular_color = float3(1.0, 1.0, 0.6);
84    float3 tnorm = normalize(mul(in_NormalMat, in_Normal));
85    float4 eye = mul(in_ModelView, float4(in_Vertex, 1.0));
86    float3 s = in_LightDir;
87    float3 v = normalize(-eye.xyz);
88    float3 r = reflect(-s, tnorm);
89    float3 ambient = ambient_color;
90    float sdotn = max(dot(s, tnorm), 0.0);
91    float3 diffuse = diffuse_color * sdotn;
92    float3 specular = float3(0.0, 0.0, 0.0);
93    if (sdotn > 0.0)
94        specular = specular_color * specular_reflect
95                 * pow(max(dot(r, v), 0.0), specular_power);
96    float3 light = ambient + diffuse + specular;
97#ifdef _XBOX
98    float4 real_color = in_Color.abgr;
99#else
100    float4 real_color = in_Color;
101#endif
102    real_color = in_Damage * float4(1.2, 1.2, 1.2, 1.0)
103               + (1.0 - in_Damage) * real_color;
104    pass_Color = real_color * float4(light, 1.0);
105    out_Position = mul(in_Proj, eye);
106}
107
108-- HLSL.Frag --
109
110void main(float4 pass_Color : COLOR,
111          out float4 out_FragColor : COLOR)
112{
113    out_FragColor = pass_Color;
114}
115
Note: See TracBrowser for help on using the repository browser.