From fed710754296111a51b1b99b40a3c5e5dc873895 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Tue, 18 Dec 2018 17:04:18 +0100 Subject: Purify collide shader i.e. move fluid vertex placement to appropriate vertex shader. Do not amplify or shift fluid moments in any way prior to passing it to the display pipeline. --- src/shader/code/vertex.glsl | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'src/shader/code/vertex.glsl') diff --git a/src/shader/code/vertex.glsl b/src/shader/code/vertex.glsl index 516f2c6..e132e5f 100644 --- a/src/shader/code/vertex.glsl +++ b/src/shader/code/vertex.glsl @@ -7,6 +7,11 @@ out VS_OUT { vec3 color; } vs_out; +uniform uint nX; +uniform uint nY; + +const float displayAmplifier = 10.0; + float unit(float x) { return 1.0/(1.0+exp(-x)); } @@ -15,8 +20,25 @@ vec3 getColor(float x) { return x*vec3(1.0,0.0,0.0) + (1-x)*vec3(-0.5,0.0,1.0); } +vec2 fluidVertexAtIndex(uint i) { + const float y = floor(float(i) / float(nX)); + return vec2( + i - nX*y, + y + ); + +} + void main() { - gl_Position = vec4(VertexPosition.xy, 0., 1.); - vs_out.color = getColor(unit(VertexPosition.z)); + const vec2 idx = fluidVertexAtIndex(gl_VertexID); + + gl_Position = vec4( + idx.x - nX/2, + idx.y - nY/2, + 0., + 1. + ); + + vs_out.color = getColor(unit(displayAmplifier * VertexPosition.z)); } )"; -- cgit v1.2.3