Skip to content

Commit c3c33e9

Browse files
authored
Merge pull request #5125 from JohnnyCena123/missing-vox-shaders
add missing shaders for glsl100, glsl120
2 parents 5b88e4f + a99649b commit c3c33e9

File tree

4 files changed

+179
-0
lines changed

4 files changed

+179
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#version 100
2+
3+
precision mediump float;
4+
5+
// Input from vertex shader
6+
varying vec3 fragPosition;
7+
varying vec4 fragColor;
8+
varying vec3 fragNormal;
9+
10+
// Uniforms
11+
uniform vec4 colDiffuse;
12+
uniform vec4 ambient;
13+
uniform vec3 viewPos;
14+
15+
#define MAX_LIGHTS 4
16+
#define LIGHT_DIRECTIONAL 0
17+
#define LIGHT_POINT 1
18+
19+
struct Light {
20+
int enabled;
21+
int type;
22+
vec3 position;
23+
vec3 target;
24+
vec4 color;
25+
};
26+
27+
uniform Light lights[MAX_LIGHTS];
28+
29+
void main()
30+
{
31+
vec3 lightDot = vec3(0.0);
32+
vec3 normal = normalize(fragNormal);
33+
vec3 viewD = normalize(viewPos - fragPosition);
34+
vec3 specular = vec3(0.0);
35+
36+
for (int i = 0; i < MAX_LIGHTS; i++)
37+
{
38+
if (lights[i].enabled == 1)
39+
{
40+
vec3 light = vec3(0.0);
41+
42+
if (lights[i].type == LIGHT_DIRECTIONAL)
43+
light = -normalize(lights[i].target - lights[i].position);
44+
45+
if (lights[i].type == LIGHT_POINT)
46+
light = normalize(lights[i].position - fragPosition);
47+
48+
float NdotL = max(dot(normal, light), 0.0);
49+
lightDot += lights[i].color.rgb * NdotL;
50+
51+
if (NdotL > 0.0)
52+
{
53+
float specCo = pow(max(0.0, dot(viewD, reflect(-light, normal))), 16.0);
54+
specular += specCo;
55+
}
56+
}
57+
}
58+
59+
vec4 finalColor = (fragColor * ((colDiffuse + vec4(specular, 1.0)) * vec4(lightDot, 1.0)));
60+
finalColor += fragColor * (ambient / 10.0) * colDiffuse;
61+
62+
finalColor = pow(finalColor, vec4(1.0/2.2)); // gamma correction
63+
64+
gl_FragColor = finalColor;
65+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#version 100
2+
3+
precision mediump float;
4+
5+
// Input vertex attributes
6+
attribute vec3 vertexPosition;
7+
attribute vec3 vertexNormal;
8+
attribute vec4 vertexColor;
9+
// attribute vec2 vertexTexCoord;
10+
11+
// Input uniform values
12+
uniform mat4 mvp;
13+
uniform mat4 matModel;
14+
uniform mat4 matNormal;
15+
16+
// Output to fragment shader
17+
varying vec3 fragPosition;
18+
varying vec4 fragColor;
19+
varying vec3 fragNormal;
20+
21+
void main()
22+
{
23+
fragPosition = vec3(matModel * vec4(vertexPosition, 1.0));
24+
fragColor = vertexColor;
25+
fragNormal = normalize(vec3(matNormal * vec4(vertexNormal, 1.0)));
26+
27+
gl_Position = mvp * vec4(vertexPosition, 1.0);
28+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#version 120
2+
// Input from vertex shader
3+
varying vec3 fragPosition;
4+
varying vec4 fragColor;
5+
varying vec3 fragNormal;
6+
7+
// Uniforms
8+
uniform vec4 colDiffuse;
9+
uniform vec4 ambient;
10+
uniform vec3 viewPos;
11+
12+
#define MAX_LIGHTS 4
13+
#define LIGHT_DIRECTIONAL 0
14+
#define LIGHT_POINT 1
15+
16+
struct Light {
17+
int enabled;
18+
int type;
19+
vec3 position;
20+
vec3 target;
21+
vec4 color;
22+
};
23+
24+
uniform Light lights[MAX_LIGHTS];
25+
26+
void main()
27+
{
28+
vec3 lightDot = vec3(0.0);
29+
vec3 normal = normalize(fragNormal);
30+
vec3 viewD = normalize(viewPos - fragPosition);
31+
vec3 specular = vec3(0.0);
32+
33+
for (int i = 0; i < MAX_LIGHTS; i++)
34+
{
35+
if (lights[i].enabled == 1)
36+
{
37+
vec3 light = vec3(0.0);
38+
39+
if (lights[i].type == LIGHT_DIRECTIONAL)
40+
light = -normalize(lights[i].target - lights[i].position);
41+
42+
if (lights[i].type == LIGHT_POINT)
43+
light = normalize(lights[i].position - fragPosition);
44+
45+
float NdotL = max(dot(normal, light), 0.0);
46+
lightDot += lights[i].color.rgb * NdotL;
47+
48+
if (NdotL > 0.0)
49+
{
50+
float specCo = pow(max(0.0, dot(viewD, reflect(-light, normal))), 16.0);
51+
specular += specCo;
52+
}
53+
}
54+
}
55+
56+
vec4 finalColor = (fragColor * ((colDiffuse + vec4(specular, 1.0)) * vec4(lightDot, 1.0)));
57+
finalColor += fragColor * (ambient / 10.0) * colDiffuse;
58+
59+
finalColor = pow(finalColor, vec4(1.0/2.2)); // gamma correction
60+
61+
gl_FragColor = finalColor;
62+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#version 120
2+
// Input vertex attributes
3+
attribute vec3 vertexPosition;
4+
attribute vec3 vertexNormal;
5+
attribute vec4 vertexColor;
6+
7+
// Uniforms
8+
uniform mat4 mvp;
9+
uniform mat4 matModel;
10+
uniform mat4 matNormal;
11+
12+
// Output to fragment shader
13+
varying vec3 fragPosition;
14+
varying vec4 fragColor;
15+
varying vec3 fragNormal;
16+
17+
void main()
18+
{
19+
fragPosition = vec3(matModel * vec4(vertexPosition, 1.0));
20+
fragColor = vertexColor;
21+
fragNormal = normalize(vec3(matNormal * vec4(vertexNormal, 1.0)));
22+
23+
gl_Position = mvp * vec4(vertexPosition, 1.0);
24+
}

0 commit comments

Comments
 (0)