source: trunk/test/shinymvtexture.lolfx @ 2838

Last change on this file since 2838 was 2816, checked in by lolbot, 7 years ago

fixed 542 files out of 2754:

  • removed 0 CR characters
  • removed 0 trailing whitespaces
  • replaced 0 tabs with spaces
  • fixed 542 svn:eol-style properties
  • Property svn:eol-style set to LF
File size: 4.2 KB
Line 
1
2[vert.glsl]
3#version 120
4
5attribute vec3 in_Vertex;
6attribute vec3 in_Normal;
7attribute vec4 in_Color;
8attribute vec2 in_TexCoord;
9
10uniform mat4 in_ModelView;
11uniform mat4 in_View;
12uniform mat4 in_Proj;
13uniform mat3 in_NormalMat;
14
15varying vec4 pass_Vertex; /* View space */
16varying vec3 pass_TNormal;
17varying vec4 pass_Color;
18varying vec2 pass_TexCoord;
19
20void main(void)
21{
22    vec4 vertex = in_ModelView * vec4(in_Vertex, 1.0);
23    vec3 tnorm = normalize(in_NormalMat * in_Normal);
24
25    pass_Vertex = vertex;
26    pass_TNormal = tnorm;
27    pass_Color = in_Color;
28    pass_TexCoord = in_TexCoord;
29
30    gl_Position = in_Proj * vertex;
31}
32
33[frag.glsl]
34#version 120
35
36#if defined GL_ES
37precision highp float;
38#endif
39
40uniform mat4 in_View;
41uniform mat4 in_Inv_View;
42uniform mat4 in_Inv_ModelView;
43uniform sampler2D u_Texture;
44
45//Light list
46uniform vec4 u_Lights[8 * 2];
47
48varying vec4 pass_Vertex; /* View space */
49varying vec3 pass_TNormal;
50varying vec4 pass_Color;
51varying vec2 pass_TexCoord;
52
53void main(void)
54{
55    /* Material properties */
56    vec3 specular_reflect = vec3(0.8, 0.75, 0.4);
57    float specular_power = 60.0;
58
59    /* World properties */
60    vec3 ambient = vec3(0.7, 0.7, 0.7);
61    vec3 specular = vec3(0.0, 0.0, 0.0);
62    vec3 diffuse = vec3(0.0, 0.0, 0.0);
63
64    /* Light precalculations */
65    vec3 v = normalize(-pass_Vertex.xyz);
66
67    /* Apply lighting */
68    for (int i = 0; i < 8; i++)
69    {
70        vec4 pos = u_Lights[i * 2];
71        vec4 color = u_Lights[i * 2 + 1];
72        vec3 s, r;
73
74        if (pos.w > 0.0)
75        {
76            /* Point light -- no attenuation yet */
77            s = normalize((in_View * pos).xyz - pass_Vertex.xyz);
78            r = reflect(-s, pass_TNormal);
79        }
80        else
81        {
82            /* Directional light */
83            s = normalize(-pos.xyz);
84            r = reflect(s, pass_TNormal);
85        }
86
87        float sdotn = max(dot(s, pass_TNormal), 0.0);
88        diffuse += color.xyz * sdotn;
89        if (sdotn > 0.0)
90            specular += color.xyz * specular_reflect
91                         * pow(max(dot(r, v), 0.0), specular_power);
92    }
93
94    vec3 light = ambient + diffuse + specular;
95
96    gl_FragColor = texture2D(u_Texture, pass_TexCoord.xy) * pass_Color * vec4(light, 1.0f);
97}
98
99[vert.hlsl]
100
101void main(float3 in_Vertex : POSITION,
102          float3 in_Normal : NORMAL,
103          float4 in_Color : COLOR,
104          uniform float4x4 in_ModelView,
105          uniform float4x4 in_Model,
106          uniform float4x4 in_Proj,
107          uniform float3x3 in_NormalMat,
108          out float4 pass_Vertex : TEXCOORD0,
109          out float3 pass_TNormal : TEXCOORD1,
110          out float4 pass_Color : COLOR,
111          out float4 out_Position : POSITION)
112{
113    float4 eye = mul(in_ModelView, float4(in_Vertex, 1.0));
114    float3 tnorm = normalize(mul(in_NormalMat, in_Normal));
115
116    pass_Vertex = eye;
117    pass_TNormal = tnorm;
118#ifdef _XBOX
119    pass_Color = in_Color.abgr;
120#else
121    pass_Color = in_Color;
122#endif
123
124    out_Position = mul(in_Proj, eye);
125}
126
127[frag.hlsl]
128
129void main(float4 pass_Vertex : TEXCOORD0,
130          float3 pass_TNormal : TEXCOORD1,
131          float4 pass_Color : COLOR,
132          uniform float in_Damage,
133          out float4 out_FragColor : COLOR)
134{
135    float3 in_LightDir = float3(0.3, 0.3, 0.7);
136
137    /* Material properties */
138    float3 specular_reflect = float3(0.8, 0.75, 0.4);
139    float specular_power = 60.0;
140
141    /* World properties */
142    float ambient_mul = 0.5;
143    float3 ambient_color = float3(0.25, 0.2, 0.35);
144    float3 diffuse_color = float3(1.0, 1.0, 0.6);
145    float3 specular_color = float3(1.0, 1.0, 0.6);
146
147    float3 s = normalize(in_LightDir); /* normalize(pass_Vertex - lightpos); */
148    float3 v = normalize(-pass_Vertex.xyz);
149    float3 r = reflect(-s, pass_TNormal);
150
151    float3 ambient = ambient_color;
152    float sdotn = max(dot(s, pass_TNormal), 0.0);
153    float3 diffuse = diffuse_color * sdotn;
154    float3 specular = float3(0.0, 0.0, 0.0);
155    if (sdotn > 0.0)
156        specular = specular_color * specular_reflect
157                 * pow(max(dot(r, v), 0.0), specular_power);
158    float3 light = ambient + diffuse + specular;
159
160    float4 real_color = in_Damage * float4(1.2, 1.2, 1.2, 1.0)
161                      + (1.0 - in_Damage) * pass_Color;
162    out_FragColor = real_color * float4(light, 1.0);
163}
164
Note: See TracBrowser for help on using the repository browser.