From 0e5cd442be3b90c041a5874fbec52659f214827e Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 19 Sep 2022 18:29:08 +0200 Subject: REVIEWED: Renamed some shaders, fix #2707 --- .../resources/shaders/glsl100/base_lighting.vs | 59 ---------------------- .../shaders/glsl100/base_lighting_instanced.vs | 36 ------------- .../shaders/resources/shaders/glsl100/lighting.vs | 59 ++++++++++++++++++++++ .../shaders/glsl100/lighting_instanced.vs | 36 +++++++++++++ .../resources/shaders/glsl120/base_lighting.vs | 59 ---------------------- .../shaders/resources/shaders/glsl120/lighting.vs | 59 ++++++++++++++++++++++ .../resources/shaders/glsl330/base_lighting.vs | 32 ------------ .../shaders/resources/shaders/glsl330/lighting.vs | 32 ++++++++++++ examples/shaders/shaders_basic_lighting.c | 2 +- examples/shaders/shaders_fog.c | 2 +- 10 files changed, 188 insertions(+), 188 deletions(-) delete mode 100644 examples/shaders/resources/shaders/glsl100/base_lighting.vs delete mode 100644 examples/shaders/resources/shaders/glsl100/base_lighting_instanced.vs create mode 100644 examples/shaders/resources/shaders/glsl100/lighting.vs create mode 100644 examples/shaders/resources/shaders/glsl100/lighting_instanced.vs delete mode 100644 examples/shaders/resources/shaders/glsl120/base_lighting.vs create mode 100644 examples/shaders/resources/shaders/glsl120/lighting.vs delete mode 100644 examples/shaders/resources/shaders/glsl330/base_lighting.vs create mode 100644 examples/shaders/resources/shaders/glsl330/lighting.vs (limited to 'examples') diff --git a/examples/shaders/resources/shaders/glsl100/base_lighting.vs b/examples/shaders/resources/shaders/glsl100/base_lighting.vs deleted file mode 100644 index 5245c615..00000000 --- a/examples/shaders/resources/shaders/glsl100/base_lighting.vs +++ /dev/null @@ -1,59 +0,0 @@ -#version 100 - -// Input vertex attributes -attribute vec3 vertexPosition; -attribute vec2 vertexTexCoord; -attribute vec3 vertexNormal; -attribute vec4 vertexColor; - -// Input uniform values -uniform mat4 mvp; -uniform mat4 matModel; - -// Output vertex attributes (to fragment shader) -varying vec3 fragPosition; -varying vec2 fragTexCoord; -varying vec4 fragColor; -varying vec3 fragNormal; - -// NOTE: Add here your custom variables - -// https://github.com/glslify/glsl-inverse -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; -} - -// https://github.com/glslify/glsl-transpose -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() -{ - // Send vertex attributes to fragment shader - fragPosition = vec3(matModel*vec4(vertexPosition, 1.0)); - fragTexCoord = vertexTexCoord; - fragColor = vertexColor; - - mat3 normalMatrix = transpose(inverse(mat3(matModel))); - fragNormal = normalize(normalMatrix*vertexNormal); - - // Calculate final vertex position - gl_Position = mvp*vec4(vertexPosition, 1.0); -} diff --git a/examples/shaders/resources/shaders/glsl100/base_lighting_instanced.vs b/examples/shaders/resources/shaders/glsl100/base_lighting_instanced.vs deleted file mode 100644 index eb47bb91..00000000 --- a/examples/shaders/resources/shaders/glsl100/base_lighting_instanced.vs +++ /dev/null @@ -1,36 +0,0 @@ -#version 100 - -// Input vertex attributes -attribute vec3 vertexPosition; -attribute vec2 vertexTexCoord; -attribute vec3 vertexNormal; -attribute vec4 vertexColor; - -attribute mat4 instanceTransform; - -// Input uniform values -uniform mat4 mvp; -uniform mat4 matNormal; - -// Output vertex attributes (to fragment shader) -varying vec3 fragPosition; -varying vec2 fragTexCoord; -varying vec4 fragColor; -varying vec3 fragNormal; - -// NOTE: Add here your custom variables - -void main() -{ - // Compute MVP for current instance - mat4 mvpi = mvp*instanceTransform; - - // Send vertex attributes to fragment shader - fragPosition = vec3(mvpi*vec4(vertexPosition, 1.0)); - fragTexCoord = vertexTexCoord; - fragColor = vertexColor; - fragNormal = normalize(vec3(matNormal*vec4(vertexNormal, 1.0))); - - // Calculate final vertex position - gl_Position = mvpi*vec4(vertexPosition, 1.0); -} diff --git a/examples/shaders/resources/shaders/glsl100/lighting.vs b/examples/shaders/resources/shaders/glsl100/lighting.vs new file mode 100644 index 00000000..5245c615 --- /dev/null +++ b/examples/shaders/resources/shaders/glsl100/lighting.vs @@ -0,0 +1,59 @@ +#version 100 + +// Input vertex attributes +attribute vec3 vertexPosition; +attribute vec2 vertexTexCoord; +attribute vec3 vertexNormal; +attribute vec4 vertexColor; + +// Input uniform values +uniform mat4 mvp; +uniform mat4 matModel; + +// Output vertex attributes (to fragment shader) +varying vec3 fragPosition; +varying vec2 fragTexCoord; +varying vec4 fragColor; +varying vec3 fragNormal; + +// NOTE: Add here your custom variables + +// https://github.com/glslify/glsl-inverse +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; +} + +// https://github.com/glslify/glsl-transpose +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() +{ + // Send vertex attributes to fragment shader + fragPosition = vec3(matModel*vec4(vertexPosition, 1.0)); + fragTexCoord = vertexTexCoord; + fragColor = vertexColor; + + mat3 normalMatrix = transpose(inverse(mat3(matModel))); + fragNormal = normalize(normalMatrix*vertexNormal); + + // Calculate final vertex position + gl_Position = mvp*vec4(vertexPosition, 1.0); +} diff --git a/examples/shaders/resources/shaders/glsl100/lighting_instanced.vs b/examples/shaders/resources/shaders/glsl100/lighting_instanced.vs new file mode 100644 index 00000000..eb47bb91 --- /dev/null +++ b/examples/shaders/resources/shaders/glsl100/lighting_instanced.vs @@ -0,0 +1,36 @@ +#version 100 + +// Input vertex attributes +attribute vec3 vertexPosition; +attribute vec2 vertexTexCoord; +attribute vec3 vertexNormal; +attribute vec4 vertexColor; + +attribute mat4 instanceTransform; + +// Input uniform values +uniform mat4 mvp; +uniform mat4 matNormal; + +// Output vertex attributes (to fragment shader) +varying vec3 fragPosition; +varying vec2 fragTexCoord; +varying vec4 fragColor; +varying vec3 fragNormal; + +// NOTE: Add here your custom variables + +void main() +{ + // Compute MVP for current instance + mat4 mvpi = mvp*instanceTransform; + + // Send vertex attributes to fragment shader + fragPosition = vec3(mvpi*vec4(vertexPosition, 1.0)); + fragTexCoord = vertexTexCoord; + fragColor = vertexColor; + fragNormal = normalize(vec3(matNormal*vec4(vertexNormal, 1.0))); + + // Calculate final vertex position + gl_Position = mvpi*vec4(vertexPosition, 1.0); +} diff --git a/examples/shaders/resources/shaders/glsl120/base_lighting.vs b/examples/shaders/resources/shaders/glsl120/base_lighting.vs deleted file mode 100644 index b1140939..00000000 --- a/examples/shaders/resources/shaders/glsl120/base_lighting.vs +++ /dev/null @@ -1,59 +0,0 @@ -#version 120 - -// Input vertex attributes -attribute vec3 vertexPosition; -attribute vec2 vertexTexCoord; -attribute vec3 vertexNormal; -attribute vec4 vertexColor; - -// Input uniform values -uniform mat4 mvp; -uniform mat4 matModel; - -// Output vertex attributes (to fragment shader) -varying vec3 fragPosition; -varying vec2 fragTexCoord; -varying vec4 fragColor; -varying vec3 fragNormal; - -// NOTE: Add here your custom variables - -// https://github.com/glslify/glsl-inverse -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; -} - -// https://github.com/glslify/glsl-transpose -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() -{ - // Send vertex attributes to fragment shader - fragPosition = vec3(matModel*vec4(vertexPosition, 1.0)); - fragTexCoord = vertexTexCoord; - fragColor = vertexColor; - - mat3 normalMatrix = transpose(inverse(mat3(matModel))); - fragNormal = normalize(normalMatrix*vertexNormal); - - // Calculate final vertex position - gl_Position = mvp*vec4(vertexPosition, 1.0); -} diff --git a/examples/shaders/resources/shaders/glsl120/lighting.vs b/examples/shaders/resources/shaders/glsl120/lighting.vs new file mode 100644 index 00000000..b1140939 --- /dev/null +++ b/examples/shaders/resources/shaders/glsl120/lighting.vs @@ -0,0 +1,59 @@ +#version 120 + +// Input vertex attributes +attribute vec3 vertexPosition; +attribute vec2 vertexTexCoord; +attribute vec3 vertexNormal; +attribute vec4 vertexColor; + +// Input uniform values +uniform mat4 mvp; +uniform mat4 matModel; + +// Output vertex attributes (to fragment shader) +varying vec3 fragPosition; +varying vec2 fragTexCoord; +varying vec4 fragColor; +varying vec3 fragNormal; + +// NOTE: Add here your custom variables + +// https://github.com/glslify/glsl-inverse +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; +} + +// https://github.com/glslify/glsl-transpose +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() +{ + // Send vertex attributes to fragment shader + fragPosition = vec3(matModel*vec4(vertexPosition, 1.0)); + fragTexCoord = vertexTexCoord; + fragColor = vertexColor; + + mat3 normalMatrix = transpose(inverse(mat3(matModel))); + fragNormal = normalize(normalMatrix*vertexNormal); + + // Calculate final vertex position + gl_Position = mvp*vec4(vertexPosition, 1.0); +} diff --git a/examples/shaders/resources/shaders/glsl330/base_lighting.vs b/examples/shaders/resources/shaders/glsl330/base_lighting.vs deleted file mode 100644 index f8ec45f1..00000000 --- a/examples/shaders/resources/shaders/glsl330/base_lighting.vs +++ /dev/null @@ -1,32 +0,0 @@ -#version 330 - -// Input vertex attributes -in vec3 vertexPosition; -in vec2 vertexTexCoord; -in vec3 vertexNormal; -in vec4 vertexColor; - -// Input uniform values -uniform mat4 mvp; -uniform mat4 matModel; -uniform mat4 matNormal; - -// Output vertex attributes (to fragment shader) -out vec3 fragPosition; -out vec2 fragTexCoord; -out vec4 fragColor; -out vec3 fragNormal; - -// NOTE: Add here your custom variables - -void main() -{ - // Send vertex attributes to fragment shader - fragPosition = vec3(matModel*vec4(vertexPosition, 1.0)); - fragTexCoord = vertexTexCoord; - fragColor = vertexColor; - fragNormal = normalize(vec3(matNormal*vec4(vertexNormal, 1.0))); - - // Calculate final vertex position - gl_Position = mvp*vec4(vertexPosition, 1.0); -} diff --git a/examples/shaders/resources/shaders/glsl330/lighting.vs b/examples/shaders/resources/shaders/glsl330/lighting.vs new file mode 100644 index 00000000..f8ec45f1 --- /dev/null +++ b/examples/shaders/resources/shaders/glsl330/lighting.vs @@ -0,0 +1,32 @@ +#version 330 + +// Input vertex attributes +in vec3 vertexPosition; +in vec2 vertexTexCoord; +in vec3 vertexNormal; +in vec4 vertexColor; + +// Input uniform values +uniform mat4 mvp; +uniform mat4 matModel; +uniform mat4 matNormal; + +// Output vertex attributes (to fragment shader) +out vec3 fragPosition; +out vec2 fragTexCoord; +out vec4 fragColor; +out vec3 fragNormal; + +// NOTE: Add here your custom variables + +void main() +{ + // Send vertex attributes to fragment shader + fragPosition = vec3(matModel*vec4(vertexPosition, 1.0)); + fragTexCoord = vertexTexCoord; + fragColor = vertexColor; + fragNormal = normalize(vec3(matNormal*vec4(vertexNormal, 1.0))); + + // Calculate final vertex position + gl_Position = mvp*vec4(vertexPosition, 1.0); +} diff --git a/examples/shaders/shaders_basic_lighting.c b/examples/shaders/shaders_basic_lighting.c index 42910a51..c557ecf7 100644 --- a/examples/shaders/shaders_basic_lighting.c +++ b/examples/shaders/shaders_basic_lighting.c @@ -57,7 +57,7 @@ int main(void) Model cube = LoadModelFromMesh(GenMeshCube(2.0f, 4.0f, 2.0f)); // Load basic lighting shader - Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/base_lighting.vs", GLSL_VERSION), + Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/lighting.vs", GLSL_VERSION), TextFormat("resources/shaders/glsl%i/lighting.fs", GLSL_VERSION)); // Get some required shader locations shader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(shader, "viewPos"); diff --git a/examples/shaders/shaders_fog.c b/examples/shaders/shaders_fog.c index 5cd68d2c..de5c23df 100644 --- a/examples/shaders/shaders_fog.c +++ b/examples/shaders/shaders_fog.c @@ -63,7 +63,7 @@ int main(void) modelC.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture; // Load shader and set up some uniforms - Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/base_lighting.vs", GLSL_VERSION), + Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/lighting.vs", GLSL_VERSION), TextFormat("resources/shaders/glsl%i/fog.fs", GLSL_VERSION)); shader.locs[SHADER_LOC_MATRIX_MODEL] = GetShaderLocation(shader, "matModel"); shader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(shader, "viewPos"); -- cgit v1.2.3