added glsl100+120 compat
This commit is contained in:
parent
351f666ec8
commit
2028348864
58
examples/shaders/resources/shaders/glsl100/cel.fs
Normal file
58
examples/shaders/resources/shaders/glsl100/cel.fs
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
#version 100
|
||||||
|
|
||||||
|
precision mediump float;
|
||||||
|
|
||||||
|
varying vec3 fragPosition;
|
||||||
|
varying vec2 fragTexCoord;
|
||||||
|
varying vec4 fragColor;
|
||||||
|
varying vec3 fragNormal;
|
||||||
|
|
||||||
|
uniform sampler2D texture0;
|
||||||
|
uniform vec4 colDiffuse;
|
||||||
|
uniform vec3 viewPos;
|
||||||
|
uniform float numBands;
|
||||||
|
|
||||||
|
struct Light {
|
||||||
|
int enabled;
|
||||||
|
int type;
|
||||||
|
vec3 position;
|
||||||
|
vec3 target;
|
||||||
|
vec4 color;
|
||||||
|
};
|
||||||
|
uniform Light lights[4];
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec4 texColor = texture2D(texture0, fragTexCoord);
|
||||||
|
vec3 baseColor = texColor.rgb * fragColor.rgb * colDiffuse.rgb;
|
||||||
|
vec3 norm = normalize(fragNormal);
|
||||||
|
|
||||||
|
float lightAccum = 0.08; // ambient floor
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
if (lights[i].enabled == 1) // no continue in GLSL ES 1.0
|
||||||
|
{
|
||||||
|
vec3 lightDir;
|
||||||
|
if (lights[i].type == 0)
|
||||||
|
{
|
||||||
|
// Directional: direction is from position toward target.
|
||||||
|
lightDir = normalize(lights[i].position - lights[i].target);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Point: direction from surface to light.
|
||||||
|
lightDir = normalize(lights[i].position - fragPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
float NdotL = max(dot(norm, lightDir), 0.0);
|
||||||
|
|
||||||
|
// Quantize NdotL into numBands discrete steps.
|
||||||
|
float quantized = min(floor(NdotL * numBands), numBands - 1.0) / (numBands - 1.0);
|
||||||
|
lightAccum += quantized * lights[i].color.r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lightAccum = clamp(lightAccum, 0.0, 1.0);
|
||||||
|
gl_FragColor = vec4(baseColor * lightAccum, texColor.a * colDiffuse.a);
|
||||||
|
}
|
||||||
48
examples/shaders/resources/shaders/glsl100/cel.vs
Normal file
48
examples/shaders/resources/shaders/glsl100/cel.vs
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
#version 100
|
||||||
|
|
||||||
|
attribute vec3 vertexPosition;
|
||||||
|
attribute vec2 vertexTexCoord;
|
||||||
|
attribute vec3 vertexNormal;
|
||||||
|
attribute vec4 vertexColor;
|
||||||
|
|
||||||
|
uniform mat4 mvp;
|
||||||
|
uniform mat4 matModel;
|
||||||
|
|
||||||
|
varying vec3 fragPosition;
|
||||||
|
varying vec2 fragTexCoord;
|
||||||
|
varying vec4 fragColor;
|
||||||
|
varying vec3 fragNormal;
|
||||||
|
|
||||||
|
// inverse() and transpose() are not built-in until GLSL 1.40 / ES 3.0
|
||||||
|
mat3 inverse(mat3 m)
|
||||||
|
{
|
||||||
|
float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2];
|
||||||
|
float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2];
|
||||||
|
float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2];
|
||||||
|
float b01 = a22*a11 - a12*a21;
|
||||||
|
float b11 = -a22*a10 + a12*a20;
|
||||||
|
float b21 = a21*a10 - a11*a20;
|
||||||
|
float det = a00*b01 + a01*b11 + a02*b21;
|
||||||
|
return mat3(b01, (-a22*a01 + a02*a21), ( a12*a01 - a02*a11),
|
||||||
|
b11, ( a22*a00 - a02*a20), (-a12*a00 + a02*a10),
|
||||||
|
b21, (-a21*a00 + a01*a20), ( a11*a00 - a01*a10)) / det;
|
||||||
|
}
|
||||||
|
|
||||||
|
mat3 transpose(mat3 m)
|
||||||
|
{
|
||||||
|
return mat3(m[0][0], m[1][0], m[2][0],
|
||||||
|
m[0][1], m[1][1], m[2][1],
|
||||||
|
m[0][2], m[1][2], m[2][2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
fragPosition = vec3(matModel * vec4(vertexPosition, 1.0));
|
||||||
|
fragTexCoord = vertexTexCoord;
|
||||||
|
fragColor = vertexColor;
|
||||||
|
|
||||||
|
mat3 normalMatrix = transpose(inverse(mat3(matModel)));
|
||||||
|
fragNormal = normalize(normalMatrix * vertexNormal);
|
||||||
|
|
||||||
|
gl_Position = mvp * vec4(vertexPosition, 1.0);
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
#version 330
|
#version 100
|
||||||
|
|
||||||
out vec4 finalColor;
|
precision mediump float;
|
||||||
|
|
||||||
void main() {
|
void main()
|
||||||
finalColor = vec4(0.05, 0.05, 0.05, 1.0);
|
{
|
||||||
}
|
gl_FragColor = vec4(0.05, 0.05, 0.05, 1.0);
|
||||||
|
}
|
||||||
|
|
@ -1,15 +1,15 @@
|
||||||
#version 330
|
#version 100
|
||||||
|
|
||||||
in vec3 vertexPosition;
|
attribute vec3 vertexPosition;
|
||||||
in vec3 vertexNormal;
|
attribute vec3 vertexNormal;
|
||||||
in vec2 vertexTexCoord;
|
attribute vec2 vertexTexCoord;
|
||||||
in vec4 vertexColor;
|
attribute vec4 vertexColor;
|
||||||
|
|
||||||
uniform mat4 mvp;
|
uniform mat4 mvp;
|
||||||
uniform float outlineThickness;
|
uniform float outlineThickness;
|
||||||
|
|
||||||
void main() {
|
void main()
|
||||||
// Extrude vertex along its normal to create the hull.
|
{
|
||||||
vec3 extruded = vertexPosition + vertexNormal * outlineThickness;
|
vec3 extruded = vertexPosition + vertexNormal * outlineThickness;
|
||||||
gl_Position = mvp * vec4(extruded, 1.0);
|
gl_Position = mvp * vec4(extruded, 1.0);
|
||||||
}
|
}
|
||||||
56
examples/shaders/resources/shaders/glsl120/cel.fs
Normal file
56
examples/shaders/resources/shaders/glsl120/cel.fs
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
#version 120
|
||||||
|
|
||||||
|
varying vec3 fragPosition;
|
||||||
|
varying vec2 fragTexCoord;
|
||||||
|
varying vec4 fragColor;
|
||||||
|
varying vec3 fragNormal;
|
||||||
|
|
||||||
|
uniform sampler2D texture0;
|
||||||
|
uniform vec4 colDiffuse;
|
||||||
|
uniform vec3 viewPos;
|
||||||
|
uniform float numBands;
|
||||||
|
|
||||||
|
struct Light {
|
||||||
|
int enabled;
|
||||||
|
int type;
|
||||||
|
vec3 position;
|
||||||
|
vec3 target;
|
||||||
|
vec4 color;
|
||||||
|
};
|
||||||
|
uniform Light lights[4];
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec4 texColor = texture2D(texture0, fragTexCoord);
|
||||||
|
vec3 baseColor = texColor.rgb * fragColor.rgb * colDiffuse.rgb;
|
||||||
|
vec3 norm = normalize(fragNormal);
|
||||||
|
|
||||||
|
float lightAccum = 0.08; // ambient floor
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
if (lights[i].enabled == 1)
|
||||||
|
{
|
||||||
|
vec3 lightDir;
|
||||||
|
if (lights[i].type == 0)
|
||||||
|
{
|
||||||
|
// Directional: direction is from position toward target.
|
||||||
|
lightDir = normalize(lights[i].position - lights[i].target);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Point: direction from surface to light.
|
||||||
|
lightDir = normalize(lights[i].position - fragPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
float NdotL = max(dot(norm, lightDir), 0.0);
|
||||||
|
|
||||||
|
// Quantize NdotL into numBands discrete steps.
|
||||||
|
float quantized = min(floor(NdotL * numBands), numBands - 1.0) / (numBands - 1.0);
|
||||||
|
lightAccum += quantized * lights[i].color.r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lightAccum = clamp(lightAccum, 0.0, 1.0);
|
||||||
|
gl_FragColor = vec4(baseColor * lightAccum, texColor.a * colDiffuse.a);
|
||||||
|
}
|
||||||
48
examples/shaders/resources/shaders/glsl120/cel.vs
Normal file
48
examples/shaders/resources/shaders/glsl120/cel.vs
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
#version 120
|
||||||
|
|
||||||
|
attribute vec3 vertexPosition;
|
||||||
|
attribute vec2 vertexTexCoord;
|
||||||
|
attribute vec3 vertexNormal;
|
||||||
|
attribute vec4 vertexColor;
|
||||||
|
|
||||||
|
uniform mat4 mvp;
|
||||||
|
uniform mat4 matModel;
|
||||||
|
|
||||||
|
varying vec3 fragPosition;
|
||||||
|
varying vec2 fragTexCoord;
|
||||||
|
varying vec4 fragColor;
|
||||||
|
varying vec3 fragNormal;
|
||||||
|
|
||||||
|
// inverse() and transpose() are not built-in until GLSL 1.40
|
||||||
|
mat3 inverse(mat3 m)
|
||||||
|
{
|
||||||
|
float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2];
|
||||||
|
float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2];
|
||||||
|
float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2];
|
||||||
|
float b01 = a22*a11 - a12*a21;
|
||||||
|
float b11 = -a22*a10 + a12*a20;
|
||||||
|
float b21 = a21*a10 - a11*a20;
|
||||||
|
float det = a00*b01 + a01*b11 + a02*b21;
|
||||||
|
return mat3(b01, (-a22*a01 + a02*a21), ( a12*a01 - a02*a11),
|
||||||
|
b11, ( a22*a00 - a02*a20), (-a12*a00 + a02*a10),
|
||||||
|
b21, (-a21*a00 + a01*a20), ( a11*a00 - a01*a10)) / det;
|
||||||
|
}
|
||||||
|
|
||||||
|
mat3 transpose(mat3 m)
|
||||||
|
{
|
||||||
|
return mat3(m[0][0], m[1][0], m[2][0],
|
||||||
|
m[0][1], m[1][1], m[2][1],
|
||||||
|
m[0][2], m[1][2], m[2][2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
fragPosition = vec3(matModel * vec4(vertexPosition, 1.0));
|
||||||
|
fragTexCoord = vertexTexCoord;
|
||||||
|
fragColor = vertexColor;
|
||||||
|
|
||||||
|
mat3 normalMatrix = transpose(inverse(mat3(matModel)));
|
||||||
|
fragNormal = normalize(normalMatrix * vertexNormal);
|
||||||
|
|
||||||
|
gl_Position = mvp * vec4(vertexPosition, 1.0);
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
#version 330
|
#version 120
|
||||||
|
|
||||||
out vec4 finalColor;
|
void main()
|
||||||
|
{
|
||||||
void main() {
|
gl_FragColor = vec4(0.05, 0.05, 0.05, 1.0);
|
||||||
finalColor = vec4(0.05, 0.05, 0.05, 1.0);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,15 @@
|
||||||
#version 330
|
#version 120
|
||||||
|
|
||||||
in vec3 vertexPosition;
|
attribute vec3 vertexPosition;
|
||||||
in vec3 vertexNormal;
|
attribute vec3 vertexNormal;
|
||||||
in vec2 vertexTexCoord;
|
attribute vec2 vertexTexCoord;
|
||||||
in vec4 vertexColor;
|
attribute vec4 vertexColor;
|
||||||
|
|
||||||
uniform mat4 mvp;
|
uniform mat4 mvp;
|
||||||
uniform float outlineThickness;
|
uniform float outlineThickness;
|
||||||
|
|
||||||
void main() {
|
void main()
|
||||||
// Extrude vertex along its normal to create the hull.
|
{
|
||||||
vec3 extruded = vertexPosition + vertexNormal * outlineThickness;
|
vec3 extruded = vertexPosition + vertexNormal * outlineThickness;
|
||||||
gl_Position = mvp * vec4(extruded, 1.0);
|
gl_Position = mvp * vec4(extruded, 1.0);
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user