STKMesh: Support splatting

This commit is contained in:
Vincent Lejeune
2014-01-18 19:03:10 +01:00
parent fbe9b26127
commit dec2cb29ec
4 changed files with 176 additions and 32 deletions

View File

@@ -4,9 +4,12 @@ uniform sampler2D tex_detail0;
uniform sampler2D tex_detail1;
uniform sampler2D tex_detail2;
uniform sampler2D tex_detail3;
//uniform sampler2D tex_detail4;
uniform sampler2D DiffuseMap;
uniform sampler2D SpecularMap;
uniform sampler2D SSAO;
uniform vec2 screen;
uniform vec3 ambient;
noperspective in vec3 nor;
in vec2 uv;
in vec2 uv_bis;
@@ -17,17 +20,20 @@ void main() {
vec4 detail1 = texture2D(tex_detail1, uv);
vec4 detail2 = texture2D(tex_detail2, uv);
vec4 detail3 = texture2D(tex_detail3, uv);
// vec4 detail4 = texture2D(tex_detail4, uv);
vec4 detail4 = vec4(0.0);
vec4 splatted = (splatting.r * detail0 +
vec4 splatted = splatting.r * detail0 +
splatting.g * detail1 +
splatting.b * detail2 +
(1.0 - splatting.r - splatting.g - splatting.b) * detail3 +
(1.0 - splatting.a) * detail4);
(1.0 - splatting.r - splatting.g - splatting.b) * detail3;
gl_FragData[0] = vec4(splatted.xyz, 1.);
vec2 tc = gl_FragCoord.xy / screen;
vec3 DiffuseComponent = texture2D(DiffuseMap, tc).xyz;
vec3 SpecularComponent = texture2D(SpecularMap, tc).xyz;
float ao = texture2D(SSAO, tc).x;
vec3 LightFactor = ao * ambient + DiffuseComponent + SpecularComponent;
gl_FragColor = vec4(splatted.xyz * LightFactor, 1.);
gl_FragData[1] = vec4(normalize(nor) * 0.5 + 0.5, gl_FragCoord.z);
gl_FragData[2] = vec4(1. - splatted.a);
// gl_FragData[2] = vec4(1. - splatted.a);
}

View File

@@ -16,18 +16,18 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#version 130
uniform vec3 lightdir;
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 TransposeInverseModelView;
noperspective out vec3 nor;
in vec3 Position;
in vec2 Texcoord;
in vec2 SecondTexcoord;
out vec2 uv;
out vec2 uv_bis;
void main()
{
uv = gl_MultiTexCoord0.st;
uv_bis = gl_MultiTexCoord1.st;
gl_Position = ModelViewProjectionMatrix * gl_Vertex;
nor = (TransposeInverseModelView * vec4(gl_Normal, 1.)).xyz;
uv = Texcoord;
uv_bis = SecondTexcoord;
gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.);
}