From c6ead0aeb6b2ab78d7d77907b2180dea98dcb473 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Mon, 24 Aug 2020 21:21:58 -0400 Subject: render: Take a stab at GLSL 1.2 compatibility. I don't have a machine to test on so this is just a best guess. I'm sure there's some bugs that other people will just have to point out to me. It's a start, at least. --- chickadee/render/phong.scm | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'chickadee/render/phong.scm') diff --git a/chickadee/render/phong.scm b/chickadee/render/phong.scm index 08bd7c7..1c718a8 100644 --- a/chickadee/render/phong.scm +++ b/chickadee/render/phong.scm @@ -118,18 +118,27 @@ layout (location = 0) in vec3 position; layout (location = 1) in vec2 texcoord; layout (location = 2) in vec3 normal; -#elif ifdef GLSL130 +#elif defined(GLSL130) in vec3 position; in vec2 texcoord; in vec3 normal; +#elif defined(GLSL120) +attribute vec3 position; +attribute vec2 texcoord; +attribute vec3 normal; #endif uniform mat4 model; uniform mat4 view; uniform mat4 projection; +#ifdef GLSL120 +varying vec3 fragNorm; +varying vec2 fragTex; +#else out vec3 fragNorm; out vec2 fragTex; +#endif void main() { gl_Position = projection * view * model * vec4(position, 1.0); @@ -161,8 +170,13 @@ struct DirectionalLight { vec3 specular; }; +#ifdef GLSL120 +attribute vec3 fragNorm; +attribute vec2 fragTex; +#else in vec3 fragNorm; in vec2 fragTex; +#endif #ifdef GLSL330 out vec4 fragColor; @@ -178,7 +192,7 @@ void main() { if(material.useAmbientMap) { #ifdef GLSL330 baseAmbientColor = texture(material.ambientMap, fragTex).xyz; -#elif ifdef GLSL130 +#else baseAmbientColor = texture2D(material.ambientMap, fragTex).xyz; #endif } else { @@ -188,7 +202,7 @@ void main() { // discard transparent fragments. #ifdef GLSL330 vec4 color = texture(material.diffuseMap, fragTex); -#elif ifdef GLSL130 +#else vec4 color = texture2D(material.diffuseMap, fragTex); #endif if(color.a == 0.0) { discard; } @@ -199,7 +213,7 @@ void main() { if(material.useSpecularMap) { #ifdef GLSL330 baseSpecularColor = texture(material.specularMap, fragTex).xyz; -#elif ifdef GLSL130 +#else baseSpecularColor = texture2D(material.specularMap, fragTex).xyz; #endif } else { @@ -217,7 +231,7 @@ void main() { vec3 specularColor = specularFactor * baseSpecularColor * material.specular; #ifdef GLSL330 fragColor = vec4(ambientColor + diffuseColor + specularColor, 1.0); -#elif ifdef GLSL130 +#else gl_FragColor = vec4(ambientColor + diffuseColor + specularColor, 1.0); #endif } -- cgit v1.2.3