init versie
This commit is contained in:
@@ -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);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user