This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
#version 330
|
||||
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
in vec3 fragPosition;
|
||||
in vec3 fragNormal;
|
||||
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 sunlightColor;
|
||||
|
||||
uniform vec3 lightDir;
|
||||
|
||||
out vec4 finalColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 texelColor = texture(texture0, fragTexCoord);
|
||||
|
||||
vec3 N = normalize(fragNormal);
|
||||
vec3 L = normalize(lightDir);
|
||||
|
||||
float ndotl = max(dot(N, L), 0.0);
|
||||
float ambient = 0.1;
|
||||
float sunfactor = ambient + (1.0 - ambient) * ndotl;
|
||||
|
||||
sunfactor *= 1+min(0, L.y);
|
||||
vec3 Lmoon = normalize(-lightDir);
|
||||
float ndotlMoon = max(dot(N, Lmoon), 0.0);
|
||||
float moonfactor = (ambient + (1.0 - ambient) * ndotlMoon) * 8;
|
||||
moonfactor *= max(0, -L.y);
|
||||
|
||||
// In fragColor, 'r' is blocklight R, 'g' is blocklight G, 'b' is blocklight B and 'a' is sunlight
|
||||
texelColor.r *= fragColor.a * sunlightColor.r * (sunfactor+moonfactor) + fragColor.r;
|
||||
texelColor.g *= fragColor.a * sunlightColor.g * (sunfactor+moonfactor) + fragColor.g;
|
||||
texelColor.b *= fragColor.a * sunlightColor.b * (sunfactor+moonfactor) + fragColor.b;
|
||||
finalColor = texelColor;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#version 330
|
||||
|
||||
// Input vertex attributes
|
||||
in vec3 vertexPosition;
|
||||
in vec2 vertexTexCoord;
|
||||
in vec3 vertexNormal;
|
||||
in vec4 vertexColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform mat4 mvp;
|
||||
uniform mat4 matModel;
|
||||
uniform mat4 matNormal;
|
||||
|
||||
// Output vertex attributes (to fragment shader)
|
||||
out vec3 fragPosition;
|
||||
out vec2 fragTexCoord;
|
||||
out vec4 fragColor;
|
||||
out vec3 fragNormal;
|
||||
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
void main()
|
||||
{
|
||||
// Send vertex attributes to fragment shader
|
||||
fragPosition = vec3(matModel*vec4(vertexPosition, 1.0));
|
||||
fragTexCoord = vertexTexCoord;
|
||||
fragColor = vertexColor;
|
||||
fragNormal = normalize(vec3(matNormal*vec4(vertexNormal, 1.0)));
|
||||
|
||||
// Calculate final vertex position
|
||||
gl_Position = mvp*vec4(vertexPosition, 1.0);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#version 330
|
||||
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
in vec3 fragPosition;
|
||||
in vec3 fragNormal;
|
||||
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 sunlightColor;
|
||||
uniform vec4 skyColor;
|
||||
|
||||
uniform vec3 lightDir;
|
||||
|
||||
out vec4 finalColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 texelColor = texture(texture0, fragTexCoord);
|
||||
|
||||
vec3 N = normalize(fragNormal);
|
||||
vec3 L = normalize(lightDir);
|
||||
|
||||
float ndotl = max(dot(N, L), 0.0);
|
||||
float ambient = 0.1;
|
||||
float sunfactor = ambient + (1.0 - ambient) * ndotl;
|
||||
|
||||
sunfactor *= 1+min(0, L.y);
|
||||
vec3 Lmoon = normalize(-lightDir);
|
||||
float ndotlMoon = max(dot(N, Lmoon), 0.0);
|
||||
float moonfactor = (ambient + (1.0 - ambient) * ndotlMoon) * 8;
|
||||
moonfactor *= max(0, -L.y);
|
||||
|
||||
// In fragColor, 'r' is blocklight R, 'g' is blocklight G, 'b' is blocklight B and 'a' is sunlight
|
||||
float sunlight = fragColor.a;
|
||||
texelColor.r *= sunlight * sunlightColor.r * (sunfactor+moonfactor) + fragColor.r;
|
||||
texelColor.g *= sunlight * sunlightColor.g * (sunfactor+moonfactor) + fragColor.g;
|
||||
texelColor.b *= sunlight * sunlightColor.b * (sunfactor+moonfactor) + fragColor.b;
|
||||
float highlight = texelColor.a;
|
||||
if(highlight < 0.25) highlight = 0;
|
||||
float highlight_final = abs(N.y)*highlight * 4;
|
||||
vec3 highlightColor = sunlightColor.rgb*highlight_final*sunlight;
|
||||
highlightColor.r += fragColor.r*highlight_final;
|
||||
highlightColor.g += fragColor.g*highlight_final;
|
||||
highlightColor.b += fragColor.b*highlight_final;
|
||||
finalColor = texelColor + vec4(highlightColor, min(1.0, highlight_final));
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#version 330
|
||||
|
||||
// Input vertex attributes
|
||||
in vec3 vertexPosition;
|
||||
in vec2 vertexTexCoord;
|
||||
in vec3 vertexNormal;
|
||||
in vec4 vertexColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform mat4 mvp;
|
||||
uniform mat4 matModel;
|
||||
uniform mat4 matNormal;
|
||||
uniform float time;
|
||||
|
||||
// Output vertex attributes (to fragment shader)
|
||||
out vec3 fragPosition;
|
||||
out vec2 fragTexCoord;
|
||||
out vec4 fragColor;
|
||||
out vec3 fragNormal;
|
||||
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
void main()
|
||||
{
|
||||
// Send vertex attributes to fragment shader
|
||||
fragPosition = vec3(matModel*vec4(vertexPosition, 1.0));
|
||||
fragTexCoord = vertexTexCoord;
|
||||
fragColor = vertexColor;
|
||||
fragNormal = normalize(vec3(matNormal*vec4(vertexNormal, 1.0)));
|
||||
|
||||
// Calculate final vertex position
|
||||
vec3 pos = vertexPosition + vec3(0, sin(time * 2.0 + vertexPosition.x * 1.5) / 20.0 + cos(time * 2.0 + vertexPosition.z * 1.5) / 20.0-0.1, 0);
|
||||
gl_Position = mvp*vec4(pos, 1.0);
|
||||
}
|
||||
Reference in New Issue
Block a user