2014-03-17 16:04:30 +00:00
|
|
|
#version 330
|
|
|
|
|
|
|
|
#extension GL_ARB_tessellation_shader : require
|
2014-01-21 15:19:07 +00:00
|
|
|
|
|
|
|
layout(triangles, equal_spacing, cw) in;
|
|
|
|
in vec3 tcPosition[];
|
|
|
|
in vec4 tcColor[];
|
|
|
|
in vec3 tcNormal[];
|
|
|
|
out vec4 teColor;
|
2014-02-07 16:15:17 +00:00
|
|
|
smooth out vec3 tePosition;
|
2014-01-21 15:19:07 +00:00
|
|
|
smooth out vec3 teNormal;
|
2014-04-22 16:06:09 +00:00
|
|
|
smooth out float fogDist;
|
2014-01-22 13:04:18 +00:00
|
|
|
smooth out float gmix; //mixture of gravel
|
2014-01-21 15:19:07 +00:00
|
|
|
//out vec3 tePatchDistance;
|
|
|
|
//constant projection matrix
|
|
|
|
uniform mat4 ProjectionMatrix;
|
|
|
|
uniform mat4 ViewMatrix;
|
|
|
|
uniform mat3 NormalMatrix;
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2014-01-22 13:04:18 +00:00
|
|
|
//NORMAL
|
2014-01-21 15:19:07 +00:00
|
|
|
vec3 n0 = gl_TessCoord.x * tcNormal[0];
|
|
|
|
vec3 n1 = gl_TessCoord.y * tcNormal[1];
|
|
|
|
vec3 n2 = gl_TessCoord.z * tcNormal[2];
|
|
|
|
vec3 tessNormal = normalize(n0 + n1 + n2);
|
|
|
|
teNormal = NormalMatrix * tessNormal;
|
|
|
|
|
2014-01-22 13:04:18 +00:00
|
|
|
//POSITION
|
|
|
|
vec3 p0 = gl_TessCoord.x * tcPosition[0];
|
|
|
|
vec3 p1 = gl_TessCoord.y * tcPosition[1];
|
|
|
|
vec3 p2 = gl_TessCoord.z * tcPosition[2];
|
|
|
|
tePosition = p0 + p1 + p2;
|
|
|
|
|
2014-01-21 15:19:07 +00:00
|
|
|
//sin(a,b) = length(cross(a,b))
|
|
|
|
float i0 = (1-gl_TessCoord.x)*gl_TessCoord.x * length(cross(tcNormal[0],tessNormal));
|
|
|
|
float i1 = (1-gl_TessCoord.y)*gl_TessCoord.y * length(cross(tcNormal[1],tessNormal));
|
|
|
|
float i2 = (1-gl_TessCoord.z)*gl_TessCoord.z * length(cross(tcNormal[2],tessNormal));
|
|
|
|
float standout = i0+i1+i2;
|
2014-01-22 13:04:18 +00:00
|
|
|
tePosition = tePosition+tessNormal*standout;
|
|
|
|
gl_Position = ProjectionMatrix * ViewMatrix * vec4(tePosition, 1);
|
2014-04-21 13:55:22 +00:00
|
|
|
fogDist = gl_Position.z;
|
2014-01-22 13:04:18 +00:00
|
|
|
|
|
|
|
//COLOR-BLENDING
|
2014-04-22 08:51:10 +00:00
|
|
|
vec4 c0 = (1-exp(gl_TessCoord.x)) * tcColor[0];
|
|
|
|
vec4 c1 = (1-exp(gl_TessCoord.y)) * tcColor[1];
|
|
|
|
vec4 c2 = (1-exp(gl_TessCoord.z)) * tcColor[2];
|
|
|
|
teColor = (c0 + c1 + c2)/((1-exp(gl_TessCoord.x))+(1-exp(gl_TessCoord.y))+(1-exp(gl_TessCoord.z)));
|
2014-01-21 15:19:07 +00:00
|
|
|
|
2014-01-22 13:04:18 +00:00
|
|
|
//mix gravel based on incline (sin (normal,up))
|
|
|
|
gmix = length(cross(tessNormal, vec3(0,1,0)));
|
2014-01-21 15:19:07 +00:00
|
|
|
|
2014-04-22 08:51:10 +00:00
|
|
|
}
|