line/curve renderer
[fishladder.git] / fishladder_resources.h
index 147f9aa748a32feba973175d54866f104e4f85b9..2bd1442d125e379b53eb589b77fc3f0b81ba8390 100644 (file)
@@ -292,12 +292,65 @@ SHADER_DEFINE( shader_background,
        UNIFORMS({ "uPv", "uOffset", "uTexMain", "uVariance", "uSamplerNoise" })
 )
 
+SHADER_DEFINE( shader_wire,
+       // VERTEX
+       "layout (location=0) in vec2 a_co;"
+       "uniform vec3 uStart;"
+       "uniform vec3 uEnd;"
+       "uniform mat3 uPv;"
+       "uniform float uCurve;"
+       ""
+       "out vec2 aTexCoords;"
+       ""
+       "vec3 sample_curve_time( float t )"
+       "{"
+               "vec3 line_coord = mix( uStart, uEnd, t );"
+
+               "float curve_amt = 1.0-(pow((t*2.0-1.0),2.0));"
+               "return vec3( line_coord.x, line_coord.y - curve_amt*uCurve, line_coord.z );"
+       "}"
+       ""
+       "void main()"
+       "{"
+               // Vertex transform
+               "vec3 p0 = sample_curve_time( a_co.x );"
+               "vec3 p1 = sample_curve_time( a_co.x + 0.025 );"
+               
+               "vec2 line_tangent = normalize(p1.xy-p0.xy);"
+               "vec2 line_normal = vec2( -line_tangent.y, line_tangent.x );"
+               
+               "vec2 worldfinal = p0.xy + line_normal*a_co.y*p0.z;"
+               
+               "gl_Position = vec4( uPv * vec3(worldfinal, 1.0), 1.0 );"
+
+               // Create texture coords (todo: include stretch adjusted coords?)
+               "aTexCoords = vec2( a_co.x, a_co.y + 0.5 );"
+       "}",
+       
+       // FRAGMENT
+       "out vec4 FragColor;"
+       ""
+       "uniform sampler2D uTexMain;"
+       "uniform vec4 uColour;"
+       ""
+       "in vec2 aTexCoords;"
+       ""
+       "void main()"
+       "{"
+               "FragColor = uColour;"
+       "}"
+       ,
+       UNIFORMS({ "uPv", "uColour", "uTexMain", "uStart", "uEnd", "uCurve" })
+)
+
+
 void vg_register(void)
 {
        SHADER_INIT( shader_tile_colour );
        SHADER_INIT( shader_tile_main );
        SHADER_INIT( shader_ball );
        SHADER_INIT( shader_background );
+       SHADER_INIT( shader_wire );
 }
 
 /*