From 40e7dda14ac4a0995059c126b7fe13ab7fec497c Mon Sep 17 00:00:00 2001 From: Faerbit Date: Sun, 1 Mar 2015 19:40:39 +0100 Subject: [PATCH] Tried adding normals for color calculation seems wrong. --- data/shader/flame.fsh | 10 +++++++++- data/shader/flame.gsh | 34 +++++++++++++++++++++++++--------- graphics.cc | 1 + 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/data/shader/flame.fsh b/data/shader/flame.fsh index ee34d2c..5296e82 100644 --- a/data/shader/flame.fsh +++ b/data/shader/flame.fsh @@ -1,10 +1,18 @@ #version 150 +uniform vec3 camera; + in vec3 fColor; +in GS_OUT { + vec3 normal; +}fs_in; + out vec4 oColor; void main() { - oColor = vec4(fColor, 0.5); + float dotProduct = dot(fs_in.normal, camera); + vec3 color = fColor * dotProduct; + oColor = vec4(color, 0.5); } diff --git a/data/shader/flame.gsh b/data/shader/flame.gsh index 6fa8e4d..4c5cf9f 100644 --- a/data/shader/flame.gsh +++ b/data/shader/flame.gsh @@ -6,7 +6,11 @@ uniform bool bottom; uniform bool left; layout(points) in; -layout(triangle_strip, max_vertices = 146) out; +layout(triangle_strip, max_vertices = 102) out; + +out GS_OUT { + vec3 normal; +}gs_out; in vec3 Color[]; out vec3 fColor; @@ -32,7 +36,7 @@ float radiusFunction(float x) { void main() { fColor = Color[0]; - float resolution = 8.0; + float resolution = 6.0; float step = abs(end-begin)/resolution/2.0; float i = 0.0; float render_end = 0.0; @@ -62,19 +66,31 @@ void main() { float rightAngle = PI * 2.0 / resolution * (j+1); vec4 offset = vec4(cos(rightAngle) * downRadius, i, -sin(rightAngle) * downRadius, 0.0); - gl_Position = gl_in[0].gl_Position + viewProjectionMatrix * offset; - EmitVertex(); + vec4 position0 = gl_in[0].gl_Position + viewProjectionMatrix * offset; offset = vec4(cos(rightAngle) * upRadius, i + step, -sin(rightAngle) * upRadius, 0.0); - gl_Position = gl_in[0].gl_Position + viewProjectionMatrix * offset; - EmitVertex(); + vec4 position1 = gl_in[0].gl_Position + viewProjectionMatrix * offset; offset = vec4(cos(leftAngle) * downRadius, i, -sin(leftAngle) * downRadius, 0.0); - gl_Position = gl_in[0].gl_Position + viewProjectionMatrix * offset; - EmitVertex(); + vec4 position2 = gl_in[0].gl_Position + viewProjectionMatrix * offset; offset = vec4(cos(leftAngle) * upRadius, i + step, -sin(leftAngle) * upRadius, 0.0); - gl_Position = gl_in[0].gl_Position + viewProjectionMatrix * offset; + vec4 position3 = gl_in[0].gl_Position + viewProjectionMatrix * offset; + + gl_Position = position0; + gs_out.normal = cross(vec3(position1) - vec3(position0), vec3(position2) - vec3(position0)); + EmitVertex(); + + gl_Position = position1; + gs_out.normal = cross(vec3(position0) - vec3(position1), vec3(position2) - vec3(position1)); + EmitVertex(); + + gl_Position = position2; + gs_out.normal = cross(vec3(position3) - vec3(position2), vec3(position3) - vec3(position2)); + EmitVertex(); + + gl_Position = position3; + gs_out.normal = cross(vec3(position1) - vec3(position3), vec3(position2) - vec3(position3)); EmitVertex(); EndPrimitive(); diff --git a/graphics.cc b/graphics.cc index d3979d0..e526e4e 100644 --- a/graphics.cc +++ b/graphics.cc @@ -242,6 +242,7 @@ void Graphics::render(double time) flameShader->use(); flameShader->setUniform("viewProjectionMatrix", lightingViewProjectionMatrix); flameShader->setUniform("time", (float) time); + flameShader->setUniform("camera", level->getPhysics()->getCameraPosition()); flameShader->setUniform("bottom", true); flameShader->setUniform("left", true); flame_positions->render();