init versie

This commit is contained in:
bart
2026-11-08 11:22:15 +01:00
commit dfd497d728
45 changed files with 3041 additions and 0 deletions
+77
View File
@@ -0,0 +1,77 @@
#version 400
uniform sampler2D tex; //this is the texture
uniform sampler2D border; //this is the texture
uniform sampler2D rock; //this is the texture
smooth in vec3 vNormal;
smooth in vec3 vWorldPos;
in vec3 fragVert;
in float z_pos;
uniform vec3 cameraPosition;
uniform mat4 modelMatrix;
in vec2 tilePos;
in vec2 fragTexCoord; //this is the texture coord
out vec4 finalColor; //this is the output color of the pixel
struct SimpleDirectionalLight
{
vec3 vColor;
vec3 vDirection;
float fAmbientIntensity;
};
uniform SimpleDirectionalLight sunLight;
vec4 GetDirectionalLightColor(SimpleDirectionalLight dirLight, vec3 vNormal)
{
float fDiffuseIntensity = dot(vNormal, -dirLight.vDirection);
float fMult = pow(dirLight.fAmbientIntensity+fDiffuseIntensity,1.0);//clamp(dirLight.fAmbientIntensity+fDiffuseIntensity, -1.0, 1.0);
// if(dirLight.iSkybox == 1)fMult = dirLight.fAmbientIntensity;
return vec4(dirLight.vColor*fMult, 1.0);
}
vec4 GetSpecularColor(vec3 vWorldPos, vec3 vEyePos, SimpleDirectionalLight dLight, vec3 vNormal)
{
vec4 vResult = vec4(0.0, 0.0, 0.0, 0.0);
vec3 vReflectedVector = normalize(reflect(dLight.vDirection, vNormal));
vec3 vVertexToEyeVector = normalize(vEyePos-vWorldPos);
float fSpecularFactor = dot(vVertexToEyeVector, vReflectedVector);
if (fSpecularFactor > 0)
{
fSpecularFactor = pow(fSpecularFactor, 1.0);
vResult = vec4(dLight.vColor, 1.0) * 1.0 * fSpecularFactor;
}
return vResult;
}
void main() {
vec3 surfaceToLight = normalize(sunLight.vDirection);
vec3 surfacePos = vec3(modelMatrix * vec4(fragVert, 1));
vec3 surfaceToCamera = normalize(cameraPosition - surfacePos);
vec4 bcolor = texture(border, vec2(tilePos.x,tilePos.y*1.154734411));
float fDiffuseIntensity = max(0.0, dot(normalize(vNormal), -sunLight.vDirection));
float addval = bcolor.a;
vec4 vSpecularColor = GetSpecularColor(vWorldPos, cameraPosition, sunLight, normalize(vNormal))+ GetDirectionalLightColor(sunLight,normalize(vNormal));
vec4 ground = texture(tex, fragTexCoord);
vec4 rockt = texture(rock, fragTexCoord);
float gndfac = 1.0;
if (z_pos>0.3)
gndfac = 0.0;
else if (z_pos>0.1)
gndfac=1.0 - 1.0 / 0.2 * (z_pos-0.1) ;
finalColor = (ground *gndfac+rockt *(1.0-gndfac) +bcolor*addval) * vSpecularColor; //texture(tex, fragTexCoord) * pow(max(0.0, dot(surfaceToCamera, reflect(-surfaceToLight, normal))), 0.5);
// (texture(tex, fragTexCoord)+bcolor*addval)*vec4(sunLight.vColor*(sunLight.fAmbientIntensity+fDiffuseIntensity), 1.0);
}
+41
View File
@@ -0,0 +1,41 @@
#version 400
uniform mat4 camera;
uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
uniform mat4 normalMatrix;
uniform mat4 modelMatrix;
layout(location = 0) in vec3 position;
layout(location = 1) in vec2 inCoord;
layout (location = 2) in float zPos;
layout (location =3) in vec3 inNormal;
//in float height;
out vec2 fragTexCoord;
out vec2 tilePos;
out vec3 fragVert;
smooth out vec3 vWorldPos;
uniform mat4 MVP;
smooth out vec3 vNormal;
out float z_pos;
void main()
{
vec4 inPositionScaled = vec4(position, 1.0);
gl_Position = MVP *vec4(position.x,position.y,zPos, 1.0);
vec4 texp= modelViewMatrix *vec4(position.x,position.y,0, 1.0);
fragTexCoord = vec2(texp.x/2,texp.y/2);
vec4 tpos = modelMatrix*vec4(position.x,position.y,0, 1.0);
tilePos = vec2(tpos.x,tpos.y);
//vColor = vec4(color, 1.0);
vec4 vRes = vec4(inNormal, 0.0);
vNormal = inNormal.xyz;
fragVert = position;
vec4 vWorldPosLocal =modelMatrix*inPositionScaled;
vWorldPos = vWorldPosLocal.xyz;
z_pos=zPos;
}