source: trunk/test/shinyfur.lolfx @ 2379

Last change on this file since 2379 was 2379, checked in by touky, 7 years ago

Added VertexDictionnary object to manage vertices with same coord && connected vertices.
Added UVs system with and UVs generation test (not very conclusive)

File size: 5.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;
13uniform float in_Damage;
14
15varying vec4 pass_Vertex; /* View space */
16varying vec3 pass_TNormal;
17varying vec4 pass_Color;
18
19void main(void)
20{
21    vec4 vertex = vec4(in_Vertex + (in_Normal * in_Damage), 1.0);
22    float dam_perc = in_Damage / (0.1 * 40);
23    vec3 vGravity = vec3(0.0, -0.981, 0.0) * 2.0;
24    float k = pow(dam_perc, 3);
25    vertex = in_ModelView * vertex + in_View * vec4(vGravity * k, 1.0);
26    vec3 tnorm = normalize(in_NormalMat * in_Normal);
27
28    pass_Vertex = vertex;
29    pass_TNormal = tnorm;
30    pass_Color = in_Color;
31
32    gl_Position = in_Proj * vertex;
33}
34
35[frag.glsl]
36#version 120
37
38#if defined GL_ES
39precision highp float;
40#endif
41
42uniform mat4 in_View;
43uniform mat4 in_Inv_View;
44uniform mat4 in_Inv_ModelView;
45uniform float in_Damage;
46
47//Light list
48uniform vec4 u_Lights[8 * 2];
49
50varying vec4 pass_Vertex; /* View space */
51varying vec3 pass_TNormal;
52varying vec4 pass_Color;
53
54void main(void)
55{
56    /* Material properties */
57    vec3 specular_reflect = vec3(0.8, 0.75, 0.4);
58    float specular_power = 60.0;
59
60    /* World properties */
61    vec3 ambient = vec3(0.7, 0.7, 0.7);
62    vec3 specular = vec3(0.0, 0.0, 0.0);
63    vec3 diffuse = vec3(0.0, 0.0, 0.0);
64
65    /* Light precalculations */
66    vec3 v = normalize(-pass_Vertex.xyz);
67
68    /* Apply lighting */
69    for (int i = 0; i < 8; i++)
70    {
71        vec4 pos = u_Lights[i * 2];
72        vec4 color = u_Lights[i * 2 + 1];
73        vec3 s, r;
74
75        if (pos.w > 0.0)
76        {
77            /* Point light -- no attenuation yet */
78            s = normalize((in_View * pos).xyz - pass_Vertex.xyz);
79            r = reflect(-s, pass_TNormal);
80        }
81        else
82        {
83            /* Directional light */
84            s = normalize(-pos.xyz);
85            r = reflect(s, pass_TNormal);
86        }
87
88        float sdotn = max(dot(s, pass_TNormal), 0.0);
89        diffuse += color.xyz * sdotn;
90        if (sdotn > 0.0)
91            specular += color.xyz * specular_reflect
92                         * pow(max(dot(r, v), 0.0), specular_power);
93    }
94
95    vec3 light = ambient + diffuse + specular;
96
97    vec4 world_vertex = in_Inv_ModelView * pass_Vertex;
98    vec4 world_normal = in_Inv_ModelView * vec4(pass_TNormal, 1.0);
99
100    float dam_perc = in_Damage / (0.1 * 40);
101    float PI = 3.14159265358979323846264;
102    dam_perc = (sin(PI * (dam_perc - 0.5)) * 0.5 + 0.5);
103    dam_perc *= dam_perc;
104    dam_perc = 1.0 - dam_perc;
105    float mod = 2.0;
106    float transp = dam_perc;
107                   /*
108                   abs(sin(world_vertex.x * mod) * dam_perc * 0.5 + 0.5) *
109                   abs(sin(world_vertex.y * mod) * dam_perc * 0.5 + 0.5) *
110                   abs(sin(world_vertex.z * mod) * dam_perc * 0.5 + 0.5)
111                   */
112
113    //vec4 real_color = mix(pass_Color, vec4(1.2, 1.2, 1.2, 1.0), in_Damage);
114    // - in_Damage
115    gl_FragColor = pass_Color * vec4(light, (in_Damage == 0)?(1.0):(transp));
116}
117
118[vert.hlsl]
119
120void main(float3 in_Vertex : POSITION,
121          float3 in_Normal : NORMAL,
122          float4 in_Color : COLOR,
123          uniform float4x4 in_ModelView,
124          uniform float4x4 in_Model,
125          uniform float4x4 in_Proj,
126          uniform float3x3 in_NormalMat,
127          out float4 pass_Vertex : TEXCOORD0,
128          out float3 pass_TNormal : TEXCOORD1,
129          out float4 pass_Color : COLOR,
130          out float4 out_Position : POSITION)
131{
132    float4 eye = mul(in_ModelView, float4(in_Vertex, 1.0));
133    float3 tnorm = normalize(mul(in_NormalMat, in_Normal));
134
135    pass_Vertex = eye;
136    pass_TNormal = tnorm;
137#ifdef _XBOX
138    pass_Color = in_Color.abgr;
139#else
140    pass_Color = in_Color;
141#endif
142
143    out_Position = mul(in_Proj, eye);
144}
145
146[frag.hlsl]
147
148void main(float4 pass_Vertex : TEXCOORD0,
149          float3 pass_TNormal : TEXCOORD1,
150          float4 pass_Color : COLOR,
151          uniform float in_Damage,
152          out float4 out_FragColor : COLOR)
153{
154    float3 in_LightDir = float3(0.3, 0.3, 0.7);
155
156    /* Material properties */
157    float3 specular_reflect = float3(0.8, 0.75, 0.4);
158    float specular_power = 60.0;
159
160    /* World properties */
161    float ambient_mul = 0.5;
162    float3 ambient_color = float3(0.25, 0.2, 0.35);
163    float3 diffuse_color = float3(1.0, 1.0, 0.6);
164    float3 specular_color = float3(1.0, 1.0, 0.6);
165
166    float3 s = normalize(in_LightDir); /* normalize(pass_Vertex - lightpos); */
167    float3 v = normalize(-pass_Vertex.xyz);
168    float3 r = reflect(-s, pass_TNormal);
169
170    float3 ambient = ambient_color;
171    float sdotn = max(dot(s, pass_TNormal), 0.0);
172    float3 diffuse = diffuse_color * sdotn;
173    float3 specular = float3(0.0, 0.0, 0.0);
174    if (sdotn > 0.0)
175        specular = specular_color * specular_reflect
176                 * pow(max(dot(r, v), 0.0), specular_power);
177    float3 light = ambient + diffuse + specular;
178
179    float4 real_color = in_Damage * float4(1.2, 1.2, 1.2, 1.0)
180                      + (1.0 - in_Damage) * pass_Color;
181    out_FragColor = real_color * float4(light, 1.0);
182}
183
Note: See TracBrowser for help on using the repository browser.