commit 8c6a0f731825ac9d324a782cb41a69a24eccb65f
parent fbc90f2a75ca30a3a6aea4edd78f0ec9e6a46584
Author: Michael Savage <mikejsavage@gmail.com>
Date: Sat, 11 Nov 2017 23:56:16 +0200
Whoops - add the skirt shader
Diffstat:
3 files changed, 60 insertions(+), 0 deletions(-)
diff --git a/shaders.cc b/shaders.cc
@@ -69,6 +69,9 @@ void shaders_init() {
shaders[ SHADER_CLIPMAP ].texture_uniform_names[ 2 ] = "horizonmap";
shaders[ SHADER_CLIPMAP ].texture_uniform_names[ 3 ] = "blue_noise";
+ shaders[ SHADER_CLIPMAP_SKIRT ].path = "shaders/clipmap_skirt.glsl";
+ shaders[ SHADER_CLIPMAP_SKIRT ].texture_uniform_names[ 0 ] = "blue_noise";
+
int failed = hotload_shaders();
if( failed != 0 ) {
FATAL( "failed to load shaders" );
diff --git a/shaders.h b/shaders.h
@@ -14,6 +14,7 @@ enum ShaderID {
SHADER_SHADOWED_VERTEX_COLOURS,
SHADER_WIREFRAME,
SHADER_CLIPMAP,
+ SHADER_CLIPMAP_SKIRT,
SHADER_COUNT,
};
diff --git a/shaders/clipmap_skirt.glsl b/shaders/clipmap_skirt.glsl
@@ -0,0 +1,56 @@
+layout( std140 ) uniform view {
+ mat4 V;
+ mat4 P;
+ vec3 camera_pos;
+};
+
+layout( std140 ) uniform sun {
+ vec3 sun_dir;
+ float sun_angle;
+};
+
+layout( std140 ) uniform clipmap_skirt {
+ vec2 bounds[ 4 ];
+};
+
+struct VSOut {
+ vec4 view_position;
+};
+
+uniform sampler2D blue_noise;
+
+#ifdef VERTEX_SHADER
+
+in vec3 position;
+out VSOut v2f;
+
+void main() {
+ if( gl_VertexID < 4 ) {
+ v2f.view_position = V * vec4( position, 1.0 );
+ }
+ else {
+ vec2 p = bounds[ gl_VertexID - 4 ];
+ v2f.view_position = V * vec4( p, 0.0, 1.0 );
+ }
+ gl_Position = P * v2f.view_position;
+}
+
+#else
+
+in VSOut v2f;
+out vec4 screen_colour;
+
+void main() {
+ vec3 normal = vec3( 0.0, 0.0, 1.0 );
+ vec3 ground = vec3( 0.0, 0.25, 1.0 );
+
+ float sunlight_lambert = max( 0, dot( normal, sun_dir ) );
+ vec3 sunlight = sunlight_lambert * vec3( 0.9, 0.9, 0.5 );
+ vec3 ambient = vec3( 0.05, 0.05, 0.15 );
+
+ vec3 c = ( sunlight + ambient ) * ground;
+
+ screen_colour = vec4( linear_to_srgb( apply_fog( c + get_dither_noise( blue_noise ), length( v2f.view_position ) ) ), 1.0 );
+}
+
+#endif