From 813d50ee94cd850a4979b6f564cd53699f99bea8 Mon Sep 17 00:00:00 2001 From: Faerbit Date: Sun, 1 Mar 2015 23:28:36 +0100 Subject: [PATCH] Tried to further improve the rendering of the flame; didn't quite work. --- data/shader/flame.fsh | 13 +++++++++---- data/shader/flame.gsh | 33 +++++++++++++++++++-------------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/data/shader/flame.fsh b/data/shader/flame.fsh index 5296e82..7a98024 100644 --- a/data/shader/flame.fsh +++ b/data/shader/flame.fsh @@ -5,14 +5,19 @@ uniform vec3 camera; in vec3 fColor; in GS_OUT { - vec3 normal; + smooth vec3 normal; + smooth vec3 position; }fs_in; out vec4 oColor; void main() { - float dotProduct = dot(fs_in.normal, camera); - vec3 color = fColor * dotProduct; - oColor = vec4(color, 0.5); + float dotProduct = dot(normalize(fs_in.normal), normalize(camera - fs_in.position)); + if (dotProduct < 0.1 && dotProduct > 0.0){ + oColor = vec4(1.0, 0.0, 0.0, 0.5); + } + else { + oColor = vec4(fColor, 0.5); + } } diff --git a/data/shader/flame.gsh b/data/shader/flame.gsh index 6f78c0c..54ff624 100644 --- a/data/shader/flame.gsh +++ b/data/shader/flame.gsh @@ -6,10 +6,11 @@ uniform bool bottom; uniform bool left; layout(points) in; -layout(triangle_strip, max_vertices = 102) out; +layout(triangle_strip, max_vertices = 78) out; out GS_OUT { - vec3 normal; + smooth vec3 normal; + smooth vec3 position; }gs_out; in vec3 Color[]; @@ -66,27 +67,31 @@ void main() { float rightAngle = PI * 2.0 / resolution * (j+1); vec4 offset = vec4(cos(rightAngle) * downRadius, i, -sin(rightAngle) * downRadius, 0.0); - vec4 position0 = gl_in[0].gl_Position + viewProjectionMatrix * offset; - gl_Position = position0; - gs_out.normal = -vec3(position0 - gl_in[0].gl_Position); + vec4 position = gl_in[0].gl_Position + viewProjectionMatrix * offset; + gl_Position = position; + gs_out.normal = vec3(position - gl_in[0].gl_Position); + gs_out.position = vec3(position); EmitVertex(); offset = vec4(cos(rightAngle) * upRadius, i + step, -sin(rightAngle) * upRadius, 0.0); - vec4 position1 = gl_in[0].gl_Position + viewProjectionMatrix * offset; - gl_Position = position1; - gs_out.normal = -vec3(position1 - gl_in[0].gl_Position); + position = gl_in[0].gl_Position + viewProjectionMatrix * offset; + gl_Position = position; + gs_out.normal = vec3(position - gl_in[0].gl_Position); + gs_out.position = vec3(position); EmitVertex(); offset = vec4(cos(leftAngle) * downRadius, i, -sin(leftAngle) * downRadius, 0.0); - vec4 position2 = gl_in[0].gl_Position + viewProjectionMatrix * offset; - gl_Position = position2; - gs_out.normal = -vec3(position2 - gl_in[0].gl_Position); + position = gl_in[0].gl_Position + viewProjectionMatrix * offset; + gl_Position = position; + gs_out.normal = vec3(position - gl_in[0].gl_Position); + gs_out.position = vec3(position); EmitVertex(); offset = vec4(cos(leftAngle) * upRadius, i + step, -sin(leftAngle) * upRadius, 0.0); - vec4 position3 = gl_in[0].gl_Position + viewProjectionMatrix * offset; - gl_Position = position3; - gs_out.normal = -vec3(position3 - gl_in[0].gl_Position); + position = gl_in[0].gl_Position + viewProjectionMatrix * offset; + gl_Position = position; + gs_out.normal = vec3(position - gl_in[0].gl_Position); + gs_out.position = vec3(position); EmitVertex(); EndPrimitive();