aboutsummaryrefslogtreecommitdiff
path: root/07-july/resources/shaders
diff options
context:
space:
mode:
authorThomas Guillermo Albers Raviola <thomas@thomaslabs.org>2026-01-16 23:02:32 +0100
committerThomas Guillermo Albers Raviola <thomas@thomaslabs.org>2026-01-16 23:02:32 +0100
commit6b8af9cf83851c075c6c9514b1deaa931c2b19a4 (patch)
tree428986b49c32e21d3f7a3c2dfa41858ae0153209 /07-july/resources/shaders
Initial commit
Diffstat (limited to '07-july/resources/shaders')
-rw-r--r--07-july/resources/shaders/passShader.frag13
-rw-r--r--07-july/resources/shaders/passShader.vert15
-rw-r--r--07-july/resources/shaders/shader.frag53
-rw-r--r--07-july/resources/shaders/shader.vert38
-rw-r--r--07-july/resources/shaders/terrainShader.frag73
-rw-r--r--07-july/resources/shaders/terrainShader.vert37
6 files changed, 229 insertions, 0 deletions
diff --git a/07-july/resources/shaders/passShader.frag b/07-july/resources/shaders/passShader.frag
new file mode 100644
index 0000000..4c8dec1
--- /dev/null
+++ b/07-july/resources/shaders/passShader.frag
@@ -0,0 +1,13 @@
+#version 420
+
+in vec4 Fragment_Color;
+in vec2 Fragment_Uv;
+
+out vec4 out_color;
+
+uniform sampler2D Texture;
+
+void main()
+{
+ out_color = Fragment_Color * texture(Texture, Fragment_Uv);
+}
diff --git a/07-july/resources/shaders/passShader.vert b/07-july/resources/shaders/passShader.vert
new file mode 100644
index 0000000..964d13e
--- /dev/null
+++ b/07-july/resources/shaders/passShader.vert
@@ -0,0 +1,15 @@
+#version 420
+
+in layout(location=0) vec2 Model_Position;
+
+uniform mat4 Matrix_totalTransform;
+
+out vec4 Fragment_Color;
+out vec2 Fragment_Uv;
+
+void main()
+{
+ Fragment_Color = vec4(1.0, 1.0, 1.0, 1.0);
+ Fragment_Uv = vec2( (Model_Position.x + 1.0)/2.0, 1.0 - (Model_Position.y + 1.0)/2.0 );
+ gl_Position = Matrix_totalTransform * vec4(Model_Position, 0.0, 1.0);
+}
diff --git a/07-july/resources/shaders/shader.frag b/07-july/resources/shaders/shader.frag
new file mode 100644
index 0000000..406d004
--- /dev/null
+++ b/07-july/resources/shaders/shader.frag
@@ -0,0 +1,53 @@
+#version 420
+
+in vec3 World_Normal;
+in vec2 Fragment_UV;
+in vec4 Fragment_Color;
+in vec3 toLightVector[4];
+in vec3 toEyeVector;
+
+out vec4 out_color;
+
+uniform vec4 lightColor[4];
+uniform vec3 attenuation[4];
+uniform sampler2D Texture;
+
+void main()
+{
+ vec4 totalDiffuse = vec4(0.0, 0.0, 0.0, 1.0);
+ vec4 totalSpecular = vec4(0.0, 0.0, 0.0, 1.0);
+
+ for(int i = 0; i < 4; i++)
+ {
+ /*Light Attenuation*/
+ float dist = length(toLightVector[i]);
+ float attFactor = attenuation[i].x + (attenuation[i].y * dist) + (attenuation[i].z * dist * dist);
+ vec3 unitToLightVector = normalize(toLightVector[i]);
+
+ /*Diffuse lighting*/
+
+ /*La intensidad es el cos entre la normal y el vector hacia la luz*/
+ float brightness = dot(unitToLightVector, normalize(World_Normal));
+ /*No queremos luz negativa ni mayor a 1*/
+ brightness = max(brightness, 0.0);
+ totalDiffuse = totalDiffuse + (brightness * lightColor[i]) / attFactor;
+
+ /* Specular lighting */
+
+ /* Reflejamos el vector hacia la luz (su inverso) en la normal */
+ vec3 Vector_ReflectedLight = reflect(-unitToLightVector, World_Normal);
+
+ /* La luz especular es el cos del angulo entre el vector hacia el ojo y la luz reflectada en la normal */
+ float specularity = clamp( dot(Vector_ReflectedLight, toEyeVector), 0, 1 );
+ float reflectivity = 1;
+ /* Que tan grande es el specular highlight */
+ specularity = pow(specularity, 10);
+ totalSpecular = totalSpecular + clamp( reflectivity * specularity * lightColor[i], 0, 1) / attFactor;
+ }
+
+ /* Ambient Light */
+ totalDiffuse = max(totalDiffuse, 0.2);
+
+ /* Juntamos todo para el color final*/
+ out_color = totalDiffuse * texture(Texture, Fragment_UV) + totalSpecular;
+}
diff --git a/07-july/resources/shaders/shader.vert b/07-july/resources/shaders/shader.vert
new file mode 100644
index 0000000..b8f10e6
--- /dev/null
+++ b/07-july/resources/shaders/shader.vert
@@ -0,0 +1,38 @@
+#version 420
+
+in layout(location=0) vec3 Model_Position;
+in layout(location=1) vec4 in_color;
+in layout(location=2) vec2 Texture_UV;
+in layout(location=3) vec3 Model_Normal;
+
+uniform mat4 Matrix_totalTransform;
+uniform mat4 Matrix_modelToWorld;
+
+uniform vec3 lightPosition[4];
+uniform vec3 World_eyePosition;
+
+out vec2 Fragment_UV;
+out vec3 World_Normal;
+out vec4 Fragment_Color;
+out vec3 toLightVector[4];
+out vec3 toEyeVector;
+
+void main()
+{
+ vec3 World_Position = vec3(Matrix_modelToWorld * vec4(Model_Position, 1.0));
+
+ for(int i = 0; i < 4; i++)
+ {
+ /* vector que apunta hacia la luz*/
+ toLightVector[i] = lightPosition[i] - World_Position;
+ }
+ /* Vector hacia el ojo*/
+ toEyeVector = normalize(World_eyePosition - World_Position);
+
+ gl_Position = Matrix_totalTransform * vec4(Model_Position, 1.0);
+ /*We add a 0 on the vec4 so we can remove the translation from the matrix
+ (WE DONT WANT THE NORMAL TO BE TRANSLATED) */
+ World_Normal = vec3(Matrix_modelToWorld * vec4(Model_Normal, 0.0));
+ Fragment_UV = vec2(Texture_UV.x, 1 - Texture_UV.y); /*Invert y axis*/
+ Fragment_Color = in_color;
+}
diff --git a/07-july/resources/shaders/terrainShader.frag b/07-july/resources/shaders/terrainShader.frag
new file mode 100644
index 0000000..be9c773
--- /dev/null
+++ b/07-july/resources/shaders/terrainShader.frag
@@ -0,0 +1,73 @@
+#version 420
+
+in vec2 Fragment_UV;
+in vec3 World_Normal;
+in vec4 Fragment_Color;
+in vec3 toLightVector[4];
+in vec3 toEyeVector;
+
+out vec4 out_color;
+
+uniform vec4 lightColor[4];
+uniform vec3 attenuation[4];
+uniform vec3 World_eyePosition;
+
+uniform sampler2D Texture_Background;
+uniform sampler2D Texture_R;
+uniform sampler2D Texture_G;
+uniform sampler2D Texture_B;
+uniform sampler2D Texture_BlendMap;
+
+void main()
+{
+ vec4 totalDiffuse = vec4(0.0, 0.0, 0.0, 1.0);
+ vec4 totalSpecular = vec4(0.0, 0.0, 0.0, 1.0);
+
+ for(int i = 0; i < 4; i++)
+ {
+ /*Light Attenuation*/
+ float dist = length(toLightVector[i]);
+ float attFactor = attenuation[i].x + (attenuation[i].y * dist) + (attenuation[i].z * dist * dist);
+ vec3 unitToLightVector = normalize(toLightVector[i]);
+ /*Diffuse lighting*/
+
+ /*La intensidad es el cos entre la normal y el vector hacia la luz*/
+ float brightness = dot(unitToLightVector, normalize(World_Normal));
+ /*No queremos luz negativa ni mayor a 1*/
+ brightness = max(brightness, 0.0);
+ totalDiffuse = totalDiffuse + (brightness * lightColor[i]) / attFactor;
+
+ /* Specular lighting */
+
+ /* Reflejamos el vector hacia la luz (su inverso) en la normal */
+ vec3 Vector_ReflectedLight = reflect(-unitToLightVector, World_Normal);
+
+ /* La luz especular es el cos del angulo entre el vector hacia el ojo y la luz reflectada en la normal */
+ float specularity = clamp( dot(Vector_ReflectedLight, toEyeVector), 0, 1 );
+ float reflectivity = 1;
+ /* Que tan grande es el specular highlight */
+ specularity = pow(specularity, 10);
+ totalSpecular = totalSpecular + clamp( reflectivity * specularity * lightColor[i], 0, 1) / attFactor;
+ }
+
+ /* Ambient Light */
+ totalDiffuse = max(totalDiffuse, 0.2);
+
+ /*Terrain color*/
+ /*The color of the current fragment from the blendmap*/
+ vec4 blendMapColor = texture(Texture_BlendMap, Fragment_UV);
+ /*We want the background color when we have black in the blend map*/
+ float backTextureAmount = 1 - (blendMapColor.r + blendMapColor.g + blendMapColor.b);
+ /*So we dont lose image quality from the tiles textures (Fragment_UV make the terrain look less HD)*/
+ vec2 Tiled_UV = Fragment_UV * 50.0f;
+ /*We get the color of each map tile (soil1, soil2, etc)*/
+ vec4 backgroundTextureColor = texture(Texture_Background, Tiled_UV) * backTextureAmount;
+ vec4 rTextureColor = texture(Texture_R, Tiled_UV) * blendMapColor.r;
+ vec4 gTextureColor = texture(Texture_G, Tiled_UV) * blendMapColor.g;
+ vec4 bTextureColor = texture(Texture_B, Tiled_UV) * blendMapColor.b;
+ /*We mix them corresponding with the blendmap*/
+ vec4 totalColor = backgroundTextureColor + rTextureColor + gTextureColor + bTextureColor;
+
+ /*Our final color for the fragment*/
+ out_color = totalDiffuse * totalColor + totalSpecular;
+}
diff --git a/07-july/resources/shaders/terrainShader.vert b/07-july/resources/shaders/terrainShader.vert
new file mode 100644
index 0000000..6abdddb
--- /dev/null
+++ b/07-july/resources/shaders/terrainShader.vert
@@ -0,0 +1,37 @@
+#version 420
+
+in layout(location=0) vec3 Model_Position;
+in layout(location=1) vec4 in_color;
+in layout(location=2) vec2 Texture_UV;
+in layout(location=3) vec3 Model_Normal;
+
+uniform mat4 Matrix_totalTransform;
+uniform mat4 Matrix_modelToWorld;
+
+uniform vec3 lightPosition[4];
+uniform vec3 World_eyePosition;
+
+out vec2 Fragment_UV;
+out vec3 World_Normal;
+out vec4 Fragment_Color;
+out vec3 toLightVector[4];
+out vec3 toEyeVector;
+
+void main()
+{
+ vec3 World_Position = vec3(Matrix_modelToWorld * vec4(Model_Position, 1.0));
+
+ for(int i = 0; i < 4; i++)
+ {
+ /* vector que apunta hacia la luz*/
+ toLightVector[i] = lightPosition[i] - World_Position;
+ }
+ /* Vector hacia el ojo*/
+ toEyeVector = normalize(World_eyePosition - World_Position);
+
+ gl_Position = Matrix_totalTransform * vec4(Model_Position, 1.0);
+ /*We add a 0 on the vec4 so we can remove the translation from the matrix
+ (WE DONT WANT THE NORMAL TO BE TRANSLATED) */
+ World_Normal = vec3(Matrix_modelToWorld * vec4(Model_Normal, 0.0));
+ Fragment_UV = vec2(Texture_UV.x, 1 - Texture_UV.y); /*Invert y axis*/
+}