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

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

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

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