From 7d82c43df91aa2584ad5bcb5d377593d59bb8d98 Mon Sep 17 00:00:00 2001 From: Tleety Date: Mon, 26 May 2014 01:08:10 +0200 Subject: [PATCH] Started work on blend maps --- src/Renderer.cpp | 1 + src/Shaders/Fragment.glsl | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/Renderer.cpp b/src/Renderer.cpp index f40e1f7..b450c97 100755 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -781,6 +781,7 @@ void Renderer::DrawFBOScene() glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, *texGroup.SpecularMap); } + //Kolla om den har blendmap, skicka då med texture 4/5/6/7 glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1); } } diff --git a/src/Shaders/Fragment.glsl b/src/Shaders/Fragment.glsl index 725bb17..35a3586 100755 --- a/src/Shaders/Fragment.glsl +++ b/src/Shaders/Fragment.glsl @@ -5,6 +5,13 @@ 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; @@ -50,9 +57,26 @@ float Shadow(vec4 ShadowCoord) void main() { - + //Fixa så den bara gör detta om modellen har en blend map + //vvvvvv + + vec4 Blend = texture2D(BlendMap, TextureCoord.st ).rgb; + vec4 AsphaltTexel = texture2D(AsphaltTexture, TextureCoord.st * texScale).rgb; + vec4 GrassTexel = texture2D(GrassTexture, TextureCoord.st * texScale).rgb; + vec4 SandTexel = texture2D(SandTexture, TextureCoord.st * texScale).rgb; + + //Mix the Terrain-textures together + AsphaltTexel *= mixmap.r; + GrassTexel = mix(AsphaltTexel, GrassTexel, mixmap.g); + vec4 tex = mix(GrassTexel, SandTexel, mixmap.b); + + //^^^^^^ + //Fixa så den bara gör detta om modellen har en blend map + + // Diffuse Texture - frag_Diffuse = texture(DiffuseTexture, Input.TextureCoord) * Shadow(Input.ShadowCoord); + frag_Diffuse = tex; + //frag_Diffuse = texture(DiffuseTexture, Input.TextureCoord) * Shadow(Input.ShadowCoord); // G-buffer Position frag_Position = vec4(Input.Position.xyz, 1.0);