72 lines
2.0 KiB
GLSL
72 lines
2.0 KiB
GLSL
#version 400 core
|
|
layout(location = 0) out vec4 out_color;
|
|
layout(location = 1) out vec4 out_position;
|
|
layout(location = 2) out vec4 out_normal;
|
|
layout(location = 3) out vec4 out_meshProperty;
|
|
layout(location = 4) out vec4 out_depth;
|
|
|
|
in vec3 lightVector;
|
|
in vec3 normal;
|
|
in vec4 worldSpacePosition;
|
|
in vec4 shadowPosition;
|
|
in vec4 fPosition;
|
|
flat in int biome;
|
|
|
|
uniform int u_renderPass;
|
|
uniform mat4 u_view;
|
|
uniform float u_dayNightFactor;
|
|
|
|
uniform sampler2D shadowMapTexture;
|
|
|
|
#define RENDER_PASS_REFLECTION 0x00
|
|
#define RENDER_PASS_REFRACTION 0x01
|
|
#define RENDER_PASS_SHADOW 0x02
|
|
#define RENDER_PASS_FINAL 0x10
|
|
|
|
#define M_PI 3.1415926535897932384626433832795
|
|
|
|
vec3 canyonTexture(vec3 position) {
|
|
vec3 bottom = vec3(0.92,0.59,0.02);
|
|
vec3 top = vec3(1.00,0.83,0.50);
|
|
float t = worldSpacePosition.y / 10;
|
|
|
|
return top * t + (1 - t) * bottom;
|
|
}
|
|
|
|
void main() {
|
|
if (u_renderPass == RENDER_PASS_REFLECTION && worldSpacePosition.y <0) {
|
|
discard;
|
|
} else if (u_renderPass == RENDER_PASS_FINAL) {
|
|
vec3 p0 = vec3(u_view * vec4(0, 0, 0, 1));
|
|
vec3 n = vec3(u_view * vec4(0, 1, 0, 0));
|
|
vec3 l = vec3(u_view * worldSpacePosition);
|
|
|
|
float d = dot(p0, n) / dot(l, n);
|
|
vec3 intersection = d*l;
|
|
float depth = 1 - length(intersection - l) / 50;
|
|
out_depth = vec4(vec3(depth), 1.0);
|
|
} else if (u_renderPass == RENDER_PASS_SHADOW) {
|
|
out_color = vec4(vec3(worldSpacePosition.z), 1);
|
|
return;
|
|
}
|
|
|
|
vec3 color;
|
|
|
|
if (biome == 1) {
|
|
color = vec3(0.92,0.90,0.64);
|
|
} else if (biome == 2){
|
|
color = vec3(0.24,0.92,0.19);
|
|
} else if (biome == 4) {
|
|
color = vec3(0.38,0.34,0.25);
|
|
} else if (biome == 8) {
|
|
color = vec3(0.92,0.92,0.22);
|
|
} else {
|
|
color = canyonTexture(worldSpacePosition.xyz);
|
|
}
|
|
//out_color = vec4(clamp(color * (0.3 + visibility * 0.7), 0.0, 1.0), 1.0);
|
|
out_color = vec4(color, 1);
|
|
out_position = worldSpacePosition;
|
|
out_normal = vec4(normal, 1);
|
|
out_meshProperty = vec4(1, biome, 0, 1);
|
|
}
|