Added blendmap component
Added renderque for models with a blendmap component Added shaders for blendmaps
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
#version 430
|
||||
|
||||
layout (binding=0) uniform sampler2D DiffuseTexture;
|
||||
layout (binding=1) uniform sampler2D ShadowTexture;
|
||||
layout (binding=2) uniform sampler2D NormalMapTexture;
|
||||
layout (binding=3) uniform sampler2D SpecularMapTexture;
|
||||
|
||||
//TerrainTextures
|
||||
layout (binding=4) uniform sampler2D TextureRed;
|
||||
layout (binding=5) uniform sampler2D TextureGreen;
|
||||
layout (binding=6) uniform sampler2D TextureBlue;
|
||||
|
||||
uniform float TextureRepeats; //Determines how many times the textures will loop over the terrain
|
||||
uniform vec3 SunDirection_cameraspace;
|
||||
uniform mat4 V;
|
||||
|
||||
in VertexData
|
||||
{
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec2 TextureCoord;
|
||||
vec4 ShadowCoord;
|
||||
vec3 Tangent;
|
||||
vec3 BiTangent;
|
||||
} Input;
|
||||
|
||||
out vec4 frag_Diffuse;
|
||||
out vec4 frag_Position;
|
||||
out vec4 frag_Normal;
|
||||
out vec4 frag_Specular;
|
||||
|
||||
float Shadow(vec4 ShadowCoord, vec3 normal)
|
||||
{
|
||||
return 1.0;
|
||||
|
||||
if (Input.ShadowCoord.x < 0.0 || Input.ShadowCoord.x > 1.0 || Input.ShadowCoord.y < 0.0 || Input.ShadowCoord.y > 1.0)
|
||||
return 0.9;
|
||||
|
||||
//Variable bias
|
||||
vec3 n = normalize(normal);
|
||||
vec3 l = normalize(SunDirection_cameraspace);
|
||||
float cosTheta = clamp(dot(n, l), 0.0, 1.0);
|
||||
float bias = tan(acos(cosTheta));
|
||||
bias = clamp(bias, 0.0, 0.00003);
|
||||
|
||||
//Fixed bias
|
||||
bias = 0;
|
||||
|
||||
if( texture(ShadowTexture, Input.ShadowCoord.xy).z < ShadowCoord.z + bias)
|
||||
{
|
||||
return 0.6;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 BlendMap = texture2D(DiffuseTexture, Input.TextureCoord.st);
|
||||
|
||||
vec4 TextureRedTexel = texture2D(TextureRed, Input.TextureCoord.st * TextureRepeats);
|
||||
vec4 TextureGreenTexel = texture2D(TextureGreen, Input.TextureCoord.st * TextureRepeats);
|
||||
vec4 TextureBlueTexel = texture2D(TextureBlue, Input.TextureCoord.st * TextureRepeats);
|
||||
|
||||
//Mix the Terrain-textures together
|
||||
TextureRedTexel *= BlendMap.r;
|
||||
TextureGreenTexel = mix(TextureRedTexel, TextureGreenTexel, BlendMap.g);
|
||||
vec4 finalBlendTexel = mix(TextureGreenTexel, TextureBlueTexel, BlendMap.b);
|
||||
|
||||
// G-buffer Position
|
||||
frag_Position = vec4(Input.Position.xyz, 1.0);
|
||||
|
||||
// G-buffer Normal
|
||||
mat3 TBN = mat3(Input.Tangent, Input.BiTangent, Input.Normal);
|
||||
frag_Normal = normalize(vec4(TBN * vec3(texture(NormalMapTexture, Input.TextureCoord)), 0.0));
|
||||
//frag_Diffuse = normalize(vec4(TBN * vec3(texture(NormalMapTexture, Input.TextureCoord)), 0.0));
|
||||
//frag_Normal = vec4(Input.Normal, 0.0);
|
||||
|
||||
// Diffuse Texture
|
||||
frag_Diffuse = finalBlendTexel * Shadow(Input.ShadowCoord, vec3(frag_Normal));
|
||||
|
||||
//G-buffer Specular
|
||||
frag_Specular = texture(SpecularMapTexture, Input.TextureCoord);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
#version 430
|
||||
|
||||
uniform mat4 MVP;
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
uniform mat4 DepthMVP;
|
||||
|
||||
layout (location = 0) in vec3 Position;
|
||||
layout (location = 1) in vec3 Normal;
|
||||
layout (location = 2) in vec2 TextureCoord;
|
||||
layout (location = 3) in vec3 Tangent;
|
||||
layout (location = 4) in vec3 BiTangent;
|
||||
|
||||
out VertexData
|
||||
{
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec2 TextureCoord;
|
||||
vec4 ShadowCoord;
|
||||
vec3 Tangent;
|
||||
vec3 BiTangent;
|
||||
} Output;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = MVP * vec4(Position, 1.0);
|
||||
|
||||
Output.Position = vec3(V * M * vec4(Position, 1.0));
|
||||
Output.Normal = normalize(vec3(inverse(transpose(V * M)) * vec4(Normal, 0.0)));
|
||||
Output.TextureCoord = TextureCoord;
|
||||
Output.ShadowCoord = DepthMVP * vec4(Position, 1.0);
|
||||
Output.Tangent = normalize(vec3(inverse(transpose(V * M)) * vec4(Tangent, 0.0)));
|
||||
Output.BiTangent = normalize(vec3(inverse(transpose(V * M)) * vec4(BiTangent, 0.0)));
|
||||
}
|
||||
@@ -5,13 +5,6 @@ layout (binding=1) uniform sampler2D ShadowTexture;
|
||||
layout (binding=2) uniform sampler2D NormalMapTexture;
|
||||
layout (binding=3) uniform sampler2D SpecularMapTexture;
|
||||
|
||||
//TerrainTextures
|
||||
layout (binding=4) uniform sampler2D AsphaltTexture;
|
||||
layout (binding=5) uniform sampler2D GrassTexture;
|
||||
layout (binding=6) uniform sampler2D SandTexture;
|
||||
layout (binding=7) uniform sampler2D BlendMap;
|
||||
|
||||
uniform float texScale; //Determines how many times the textures will loop over the terrain
|
||||
uniform vec3 SunDirection_cameraspace;
|
||||
uniform mat4 V;
|
||||
|
||||
@@ -59,25 +52,6 @@ float Shadow(vec4 ShadowCoord, vec3 normal)
|
||||
|
||||
void main()
|
||||
{
|
||||
//Fixa så den bara gör detta om modellen har en blend map
|
||||
//vvvvvv
|
||||
|
||||
vec4 Blend = texture2D(BlendMap, Input.TextureCoord.st );
|
||||
vec4 AsphaltTexel = texture2D(AsphaltTexture, Input.TextureCoord.st * texScale);
|
||||
vec4 GrassTexel = texture2D(GrassTexture, Input.TextureCoord.st * texScale);
|
||||
vec4 SandTexel = texture2D(SandTexture, Input.TextureCoord.st * texScale);
|
||||
|
||||
//Mix the Terrain-textures together
|
||||
AsphaltTexel *= Blend.r;
|
||||
GrassTexel = mix(AsphaltTexel, GrassTexel, Blend.g);
|
||||
vec4 tex = mix(GrassTexel, SandTexel, Blend.b);
|
||||
|
||||
//^^^^^^
|
||||
//Fixa så den bara gör detta om modellen har en blend map
|
||||
|
||||
|
||||
|
||||
|
||||
// G-buffer Position
|
||||
frag_Position = vec4(Input.Position.xyz, 1.0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user