From 8b7d2d6c1a9e61585a34e411c10dd267bf45888f Mon Sep 17 00:00:00 2001 From: Stefan Dresselhaus Date: Tue, 21 Jan 2014 16:19:07 +0100 Subject: [PATCH] forgot shaders -.- --- shaders/tessControl.shader | 26 +++++++++++++++++++++++ shaders/tessEval.shader | 42 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 shaders/tessControl.shader create mode 100644 shaders/tessEval.shader diff --git a/shaders/tessControl.shader b/shaders/tessControl.shader new file mode 100644 index 0000000..36bae7f --- /dev/null +++ b/shaders/tessControl.shader @@ -0,0 +1,26 @@ +#version 400 + +layout(vertices = 3) out; +in vec3 vPosition[]; +in vec4 vColor[]; +in vec3 vNormal[]; +out vec3 tcPosition[]; +out vec4 tcColor[]; +out vec3 tcNormal[]; +uniform float TessLevelInner = 1.0; // controlled by keyboard buttons +uniform float TessLevelOuter = 1.0; // controlled by keyboard buttons + +#define ID gl_InvocationID + +void main() +{ + tcPosition[ID] = vPosition[ID]; + tcColor[ID] = vColor[ID]; + tcNormal[ID] = vNormal[ID]; + if (ID == 0) { + gl_TessLevelInner[0] = TessLevelInner; + gl_TessLevelOuter[0] = TessLevelOuter; + gl_TessLevelOuter[1] = TessLevelOuter; + gl_TessLevelOuter[2] = TessLevelOuter; + } +} \ No newline at end of file diff --git a/shaders/tessEval.shader b/shaders/tessEval.shader new file mode 100644 index 0000000..35ae2d7 --- /dev/null +++ b/shaders/tessEval.shader @@ -0,0 +1,42 @@ +#version 400 + +layout(triangles, equal_spacing, cw) in; +in vec3 tcPosition[]; +in vec4 tcColor[]; +in vec3 tcNormal[]; +//out vec3 tePosition; +out vec4 teColor; +smooth out vec3 teNormal; +//out vec3 tePatchDistance; +//constant projection matrix +uniform mat4 ProjectionMatrix; +uniform mat4 ViewMatrix; +uniform mat3 NormalMatrix; + +void main() +{ + vec3 p0 = gl_TessCoord.x * tcPosition[0]; + vec3 p1 = gl_TessCoord.y * tcPosition[1]; + vec3 p2 = gl_TessCoord.z * tcPosition[2]; + //tePatchDistance = gl_TessCoord; + vec3 tePosition = p0 + p1 + p2; + + 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; + + //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; + + vec4 c0 = gl_TessCoord.x * tcColor[0]; + vec4 c1 = gl_TessCoord.y * tcColor[1]; + vec4 c2 = gl_TessCoord.z * tcColor[2]; + teColor = c0 + c1 + c2; + + gl_Position = ProjectionMatrix * ViewMatrix * vec4(tePosition+tessNormal*standout, 1); +} \ No newline at end of file