summaryrefslogtreecommitdiffstats
path: root/cwd/shaders
diff options
context:
space:
mode:
Diffstat (limited to 'cwd/shaders')
-rw-r--r--cwd/shaders/entity.fs2
-rw-r--r--cwd/shaders/face.fs4
-rw-r--r--cwd/shaders/face.vs3
-rw-r--r--cwd/shaders/sky.fs49
-rw-r--r--cwd/shaders/sky.vs17
5 files changed, 74 insertions, 1 deletions
diff --git a/cwd/shaders/entity.fs b/cwd/shaders/entity.fs
index 6935d1b..f0bb42f 100644
--- a/cwd/shaders/entity.fs
+++ b/cwd/shaders/entity.fs
@@ -4,6 +4,6 @@ uniform vec3 color;
in vec2 uvPos;
void main(){
- if (uvPos.x < 0.9 && uvPos.x > 0.1 && uvPos.y < 0.9 && uvPos.y > 0.1) discard;
+ //if (uvPos.x < 0.9 && uvPos.x > 0.1 && uvPos.y < 0.9 && uvPos.y > 0.1) discard;
gl_FragColor = vec4(color,1);
} \ No newline at end of file
diff --git a/cwd/shaders/face.fs b/cwd/shaders/face.fs
index 4710f90..6e9d8f0 100644
--- a/cwd/shaders/face.fs
+++ b/cwd/shaders/face.fs
@@ -4,6 +4,7 @@ in VS_OUT {
vec2 UvPosition;
vec4 Texture;
vec3 Color;
+ vec2 Light;
} fs_in;
uniform sampler2D textureAtlas;
@@ -44,4 +45,7 @@ void main() {
vec3 hsvColor = rgb2hsv(gl_FragColor.xyz);
hsvColor+=fs_in.Color;
gl_FragColor = vec4(hsv2rgb(hsvColor),1);
+// gl_FragColor = vec4(fs_in.Light.x / 16.0,0,fs_in.Light.y / 16.0,1);
+ float faceLight = clamp((fs_in.Light.x + fs_in.Light.y) / 16.0,0,16);
+ gl_FragColor = vec4(gl_FragColor.rgb * faceLight,gl_FragColor.a);
} \ No newline at end of file
diff --git a/cwd/shaders/face.vs b/cwd/shaders/face.vs
index 95818ef..9bf2639 100644
--- a/cwd/shaders/face.vs
+++ b/cwd/shaders/face.vs
@@ -4,11 +4,13 @@ layout (location = 2) in vec2 UvCoordinates;
layout (location = 7) in vec4 Texture;
layout (location = 8) in mat4 model;
layout (location = 12) in vec3 color;
+layout (location = 13) in vec2 light;
out VS_OUT {
vec2 UvPosition;
vec4 Texture;
vec3 Color;
+ vec2 Light;
} vs_out;
uniform mat4 view;
@@ -22,4 +24,5 @@ void main()
vs_out.UvPosition = vec2(UvCoordinates.x,UvCoordinates.y);
vs_out.Texture = Texture;
vs_out.Color = color;
+ vs_out.Light = light;
}
diff --git a/cwd/shaders/sky.fs b/cwd/shaders/sky.fs
new file mode 100644
index 0000000..549d463
--- /dev/null
+++ b/cwd/shaders/sky.fs
@@ -0,0 +1,49 @@
+#version 330 core
+
+in vec2 uvPos;
+in vec3 pos;
+
+uniform sampler2D textureAtlas;
+uniform vec4 skyTexture;
+uniform float DayTime;
+uniform vec4 sunTexture;
+uniform vec4 moonTexture;
+
+const vec4 DaySkyColor = vec4(0.49,0.66,1, 1);
+
+const vec3 SunPos = vec3(0,0.1,0.5);
+
+const vec3 MoonPos = vec3(0,0.1,-0.5);
+
+vec2 TransformTextureCoord(vec4 TextureAtlasCoords, vec2 UvCoords) {
+ float x = TextureAtlasCoords.x;
+ float y = TextureAtlasCoords.y;
+ float w = TextureAtlasCoords.z;
+ float h = TextureAtlasCoords.w;
+ vec2 A = vec2(x, 1 - y - h);
+ vec2 B = vec2(x + w, 1 - y);
+ return A + UvCoords * (B - A);
+}
+
+vec4 Sun() {
+ vec3 sunDelta = (pos - SunPos)*3.0f;
+ float distanceToSun = length(sunDelta);
+ vec4 sunColor = texture(textureAtlas,TransformTextureCoord(sunTexture,(vec2(sunDelta.xy)+0.5f)));
+ vec4 sun = mix(vec4(0,0,0,1),sunColor,clamp(1-distanceToSun*2.0f,0,1));
+ return sun;
+}
+
+vec4 Moon() {
+ vec3 moonDelta = (pos - MoonPos)*4.5f;
+ float distanceToMoon = length(moonDelta);
+ vec4 moonColor = texture(textureAtlas,TransformTextureCoord(moonTexture,(vec2(moonDelta.xy)+0.5f)));
+ vec4 moon = mix(vec4(0,0,0,1),moonColor,clamp(1-distanceToMoon*2.0f,0,1));
+ return moon;
+}
+
+void main() {
+ vec4 starColor = texture(textureAtlas,TransformTextureCoord(skyTexture,uvPos));
+ gl_FragColor = mix(starColor, DaySkyColor, DayTime);
+ gl_FragColor += Sun();
+ gl_FragColor += Moon();
+} \ No newline at end of file
diff --git a/cwd/shaders/sky.vs b/cwd/shaders/sky.vs
new file mode 100644
index 0000000..983e1f3
--- /dev/null
+++ b/cwd/shaders/sky.vs
@@ -0,0 +1,17 @@
+#version 330 core
+
+uniform mat4 view;
+uniform mat4 projection;
+uniform mat4 model;
+
+layout (location = 0) in vec3 position;
+layout (location = 1) in vec2 uvPosition;
+
+out vec2 uvPos;
+out vec3 pos;
+
+void main(){
+ uvPos = uvPosition;
+ pos = position;
+ gl_Position = projection*view*model*vec4(position,1);
+} \ No newline at end of file