source: trunk/src/easymesh/shinydebugnormal.lolfx @ 2370

Last change on this file since 2370 was 2370, checked in by touky, 6 years ago

render : Added DebugRenderMode & corresponding shaders. naive (VERY) implementation in MeshViewer.

File size: 3.2 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_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
41uniform vec4 u_Lights[8 * 2];
42
43varying vec4 pass_Vertex; /* View space */
44varying vec3 pass_TNormal;
45varying vec4 pass_Color;
46
47void main(void)
48{
49    vec3 real_color = vec3(0.0, 0.0, 0.0);
50    real_color += abs(pass_TNormal.x) * ((pass_TNormal.x < .0f)?(vec3(0.0, 1.0, 1.0)):(vec3(1.0, 0.0, 0.0)));
51    real_color += abs(pass_TNormal.y) * ((pass_TNormal.y < .0f)?(vec3(1.0, 0.0, 1.0)):(vec3(0.0, 1.0, 0.0)));
52    real_color += abs(pass_TNormal.z) * ((pass_TNormal.z < .0f)?(vec3(1.0, 1.0, 0.0)):(vec3(0.0, 0.0, 1.0)));
53    gl_FragColor = vec4(real_color, pass_Color.w);
54}
55
56[vert.hlsl]
57
58void main(float3 in_Vertex : POSITION,
59          float3 in_Normal : NORMAL,
60          float4 in_Color : COLOR,
61          uniform float4x4 in_ModelView,
62          uniform float4x4 in_Model,
63          uniform float4x4 in_Proj,
64          uniform float3x3 in_NormalMat,
65          out float4 pass_Vertex : TEXCOORD0,
66          out float3 pass_TNormal : TEXCOORD1,
67          out float4 pass_Color : COLOR,
68          out float4 out_Position : POSITION)
69{
70    float4 eye = mul(in_ModelView, float4(in_Vertex, 1.0));
71    float3 tnorm = normalize(mul(in_NormalMat, in_Normal));
72
73    pass_Vertex = eye;
74    pass_TNormal = tnorm;
75#ifdef _XBOX
76    pass_Color = in_Color.abgr;
77#else
78    pass_Color = in_Color;
79#endif
80
81    out_Position = mul(in_Proj, eye);
82}
83
84[frag.hlsl]
85
86void main(float4 pass_Vertex : TEXCOORD0,
87          float3 pass_TNormal : TEXCOORD1,
88          float4 pass_Color : COLOR,
89          uniform float in_Damage,
90          out float4 out_FragColor : COLOR)
91{
92    float3 in_LightDir = float3(0.3, 0.3, 0.7);
93
94    /* Material properties */
95    float3 specular_reflect = float3(0.8, 0.75, 0.4);
96    float specular_power = 60.0;
97
98    /* World properties */
99    float ambient_mul = 0.5;
100    float3 ambient_color = float3(0.25, 0.2, 0.35);
101    float3 diffuse_color = float3(1.0, 1.0, 0.6);
102    float3 specular_color = float3(1.0, 1.0, 0.6);
103
104    float3 s = normalize(in_LightDir); /* normalize(pass_Vertex - lightpos); */
105    float3 v = normalize(-pass_Vertex.xyz);
106    float3 r = reflect(-s, pass_TNormal);
107
108    float3 ambient = ambient_color;
109    float sdotn = max(dot(s, pass_TNormal), 0.0);
110    float3 diffuse = diffuse_color * sdotn;
111    float3 specular = float3(0.0, 0.0, 0.0);
112    if (sdotn > 0.0)
113        specular = specular_color * specular_reflect
114                 * pow(max(dot(r, v), 0.0), specular_power);
115    float3 light = ambient + diffuse + specular;
116
117    float4 real_color = in_Damage * float4(1.2, 1.2, 1.2, 1.0)
118                      + (1.0 - in_Damage) * pass_Color;
119    out_FragColor = real_color * float4(light, 1.0);
120}
121
Note: See TracBrowser for help on using the repository browser.