-// SHADERS
-// ===========================================================================================================
-
-SHADER_DEFINE( shader_tile_colour,
-
- // VERTEX
- "layout (location=0) in vec2 a_co;"
- "uniform mat3 uPv;"
- "uniform vec3 uOffset;"
- ""
- "void main()"
- "{"
- "gl_Position = vec4( uPv * vec3( a_co * uOffset.z + uOffset.xy, 1.0 ), 1.0 );"
- "}",
-
- // FRAGMENT
- "out vec4 FragColor;"
- "uniform vec4 uColour;"
- ""
- "void main()"
- "{"
- "FragColor = uColour;"
- "}"
- ,
- UNIFORMS({ "uPv", "uOffset", "uColour" })
-)
-
-SHADER_DEFINE( shader_ball,
- // VERTEX
- "layout (location=0) in vec2 a_co;"
- "uniform vec3 uOffset;"
- "uniform mat3 uPv;"
- ""
- "out vec4 aTexCoords;"
- ""
- "void main()"
- "{"
- // Vertex transform
- "vec3 worldpos = vec3( (a_co * 0.5 - 0.25) * uOffset.z + uOffset.xy, 1.0 );"
- "gl_Position = vec4( uPv * worldpos, 1.0 );"
-
- // Create texture coords
- "aTexCoords = vec4( a_co, worldpos.xy );"
- "}",
-
- // FRAGMENT
- "out vec4 FragColor;"
- ""
- "uniform sampler2D uTexMain;"
- "uniform vec3 uColour;"
- "uniform vec2 uTexOffset;"
- ""
- "in vec4 aTexCoords;"
- ""
- "void main()"
- "{"
- "vec2 center_coords = aTexCoords.xy - 0.5;"
- "vec2 center_coords_sqr = center_coords*center_coords;"
- "float circle_factor = smoothstep( 0.07, 0.0625, center_coords_sqr.x+center_coords_sqr.y );"
-
- "float bulge_amt = center_coords_sqr.x+center_coords_sqr.y;"
- "vec2 warped_coords = aTexCoords.zw+uTexOffset - center_coords;"
- "vec4 noise_sample = texture( uTexMain, warped_coords );"
-
- "float rim_light = (center_coords_sqr.x+center_coords_sqr.y)*15.0;"
-
- "vec2 shadow_coords = center_coords + vec2(0.02,0.07);"
- "vec2 shadow_coords_sqr = shadow_coords*shadow_coords;"
- "float shadow = exp(-((shadow_coords_sqr.x+shadow_coords_sqr.y)-0.0125)*15.0);"
-
- "vec3 marble_comp = uColour*0.6 + (noise_sample.x*2.7+pow(rim_light,3.0)*2.0) * 0.1;"
- //"vec4 colour_comp = mix( vec4(0.74,0.53,0.34,shadow), vec4(marble_comp,1.0), circle_factor );"
- "vec4 colour_comp = mix( vec4(0.0,0.0,0.0,shadow), vec4(marble_comp,1.0), circle_factor );"
-
- "FragColor = colour_comp;"
- "}"
- ,
- UNIFORMS({ "uTexMain", "uColour", "uOffset", "uPv", "uTexOffset" })
-)
-
-SHADER_DEFINE( shader_tile_main,
- // VERTEX
- "layout (location=0) in vec2 a_co;"
- "uniform vec4 uOffset;" // Tile x/y, uv x/y
- "uniform mat3 uPv;"
- "uniform mat2 uSubTransform;"
- "uniform float uVisibility;"
- ""
- "out vec4 aTexCoords;"
- "out vec2 aWorldCoords;"
- ""
- "vec2 hash22(vec2 p)"
- "{"
- "vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));"
- "p3 += dot(p3, p3.yzx+33.33);"
- "return fract((p3.xx+p3.yz)*p3.zy);"
- "}"
- ""
- "void main()"
- "{"
- "vec2 hash_val = hash22(uOffset.xy);"
- "float scaling_factor = smoothstep( hash_val.x, hash_val.x+1.0, uVisibility );"
-
- // Vertex transform
- "vec2 subtransform = uSubTransform * (a_co-0.5) * scaling_factor + 0.5;"
- "vec3 worldpos = vec3( subtransform + uOffset.xy, 1.0 );"
- "gl_Position = vec4( uPv * worldpos, 1.0 );"
-
- // Create texture coords
- "vec2 random_offset = floor(hash_val * 4.0) * 0.25;"
- "vec2 edge_safe_coords = a_co * 0.98 + 0.01;"
- "aTexCoords = vec4((edge_safe_coords + uOffset.zw) * 0.25, edge_safe_coords * 0.25 + random_offset );"
- "aWorldCoords = worldpos.xy;"
- "}",
-
- // FRAGMENT
- "out vec4 FragColor;"
- ""
- "uniform sampler2D uTexGlyphs;"
- "uniform sampler2D uTexGlow;"
- "uniform sampler2D uTexWood;"
- "uniform float uGhost;"
- "uniform float uForeground;"
- "uniform vec2 uMousePos;"
- "uniform vec4 uColour;"
- "uniform vec3 uShadowing;"
- "uniform vec3 uGlowA;"
- "uniform vec3 uGlowB;"
- ""
- "in vec4 aTexCoords;"
- "in vec2 aWorldCoords;"
- ""
- "void main()"
- "{"
- //"vec3 shadowing_colour = vec3( 0.93, 0.88536, 0.8184 ) * 0.97;"
- //"vec3 shadowing_colour = vec3( 0.8, 0.8, 0.8 );"
-
- "vec4 glyph = texture( uTexGlyphs, aTexCoords.xy );"
- "vec4 glyph_glow = texture( uTexGlow, aTexCoords.xy );"
- "vec4 wood = texture( uTexWood, aTexCoords.zw );"
- "vec4 wood_secondary = texture( uTexWood, aTexCoords.zw + 0.25 );"
- "vec3 wood_comp = mix( wood_secondary.rgb * uShadowing, wood.rgb, clamp( glyph.b*2.0-1.0, 0.0, 1.0 ) );"
-
- //"vec3 shadows = mix( vec3( 0.85, 0.7344, 0.561 ), vec3(1.0,1.0,1.0), glyph.r );"
- "vec3 shadows = mix( uShadowing, vec3(1.0,1.0,1.0), glyph.r );"
-
- "vec4 output_regular = vec4( wood_comp * shadows, mix( glyph.a, glyph.b, uForeground ) );"
-
- "float ghost_dist = clamp( 1.5 - distance(uMousePos, aWorldCoords), 0.0, 1.0 );"
- "vec4 output_ghost = vec4( 1.0, 1.0, 1.0, glyph.g*ghost_dist );"
- "vec4 glow_comp = vec4(glyph_glow.b*uGlowA+glyph_glow.g*uGlowB,0.0);"
-
- "FragColor = mix( output_regular, output_ghost, uGhost )*uColour + glow_comp;"
- "}"
- ,
- UNIFORMS({ "uPv", "uOffset", "uTexGlyphs", "uTexWood", "uSubTransform", "uGhost", "uMousePos",
- "uColour", "uForeground", "uVisibility", "uShadowing", "uTexGlow",
- "uGlowA", "uGlowB" })
-)
-
-SHADER_DEFINE( shader_background,
- // VERTEX
- "layout (location=0) in vec2 a_co;"
- "uniform mat3 uPv;"
- "uniform vec3 uOffset;"
- ""
- "out vec2 aTexCoords;"
- ""
- "void main()"
- "{"
- "vec2 world_pos = a_co * uOffset.z + uOffset.xy;"
- "gl_Position = vec4( uPv * vec3( world_pos, 1.0 ), 1.0 );"
- "aTexCoords = a_co;"
- "}",
-
- // FRAGMENT
- "out vec4 FragColor;"
- ""
- "uniform sampler2D uTexMain;"
- "uniform sampler2D uSamplerNoise;"
- "uniform float uVariance;"
- "uniform float uVisibility;"
- ""
- "in vec2 aTexCoords;"
- ""
- "void main()"
- "{"
- "vec4 data_this_tile = texture( uTexMain, aTexCoords );"
-
- "float ao_accum = 0.0;"
-
- "vec2 random_noise;"
-
- "for( int i=0; i<10; ++i )"
- "{"
- "random_noise = (texture( uSamplerNoise, aTexCoords * 10.0 + float(i) * 0.2 ).xy - vec2( 0.5, 0.5 )) * uVariance;"
- "vec4 background = texture( uTexMain, aTexCoords + random_noise );"
- "float height_diff = min(data_this_tile.r - background.r,0.0);"
-
- "ao_accum += height_diff * clamp((1.0 - length( random_noise )), 0.0, 1.0);"
- "}"
- "ao_accum *= 0.15;"
-
-#if 0
- "vec3 colour_main = mix( vec3( 0.369768, 0.3654, 0.42 ), vec3( 0.275, 0.388, 0.553 ), data_this_tile.g * uVisibility );"
-#endif
-
- "vec2 square_coords = fract( aTexCoords * 64.0 );"
- "vec2 grid_coords = abs( square_coords - 0.5 );"
- "float gridline = step( 0.49, max(grid_coords.x,grid_coords.y) );"
-
- "vec3 colour_main = mix( vec3( 0.14 ) + random_noise.x*0.5, vec3( 0.1 ) + gridline*0.02, data_this_tile.g * uVisibility );"
- "FragColor = vec4( colour_main + ao_accum*0.05, 1.0 );"
- "}"
- ,
- UNIFORMS({ "uPv", "uOffset", "uTexMain", "uVariance", "uSamplerNoise", "uVisibility" })
-)
-
-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;"
- "uniform float uTime;"
- "uniform float uGlow;"
- ""
- "in vec2 aTexCoords;"
- ""
- "void main()"
- "{"
- // Compute shadowing
- "float shadow = 1.0 - abs(aTexCoords.y - 0.5) * 2.0;"
- "float masking = smoothstep( 0.5, 0.8, shadow );"
-
- "vec3 colour_comp = mix( vec3(0.0,0.0,0.0), uColour.rgb, masking );"
-
- "float flow_thing = fract( aTexCoords.x + uTime );"
- "vec3 final_comp = colour_comp + flow_thing * uGlow;"
-
- "FragColor = vec4( final_comp, max( shadow* 0.2, masking ) * uColour.a );"
- "}"
- ,
- UNIFORMS({ "uPv", "uColour", "uTexMain", "uStart", "uEnd", "uCurve", "uTime", "uGlow" })
-)
-
-SHADER_DEFINE( shader_buttons,
- // VERTEX
- "layout (location=0) in vec2 a_co;"
- "uniform vec4 uOffset;" // Tile x/y, uv x/y
- "uniform mat3 uPv;"
- ""
- "out vec2 aTexCoords;"
- ""
- "void main()"
- "{"
- // Vertex transform
- "vec3 worldpos = vec3( a_co + uOffset.xy, 1.0 );"
- "gl_Position = vec4( uPv * worldpos, 1.0 );"
-
- // Create texture coords
- "vec2 edge_safe_coords = a_co * 0.98 + 0.01;"
- "aTexCoords = (edge_safe_coords + uOffset.zw) * 0.25;"
- "}",
-
- // FRAGMENT
- "out vec4 FragColor;"
- ""
- "uniform sampler2D uTexMain;"
- "uniform vec4 uColour;" // rgb, light amount
- ""
- "in vec2 aTexCoords;"
- ""
- "void main()"
- "{"
- "vec4 glyph = texture( uTexMain, aTexCoords.xy );"
-
- "FragColor = vec4( uColour.rgb * (mix(glyph.r, glyph.g, uColour.a)+0.02)*2.6 + glyph.b * 0.4, glyph.a );"
- "}"
- ,
- UNIFORMS({ "uPv", "uOffset", "uTexMain", "uColour" })
-)
-
-SHADER_DEFINE( shader_sprite,
-
- // VERTEX
- "layout (location=0) in vec2 a_co;" // quad mesh
- "uniform vec4 uUv;"
- "uniform vec3 uPos;"
- ""
- "uniform mat3 uPv;"
- ""
- "out vec2 aTexCoords;"
- ""
- "void main()"
- "{"
- "vec2 vertex_world = uUv.zw * (a_co-0.5) * uPos.z + uPos.xy;"
- "gl_Position = vec4( uPv * vec3( vertex_world, 1.0 ), 1.0 );"
- "aTexCoords = uUv.xy + a_co*uUv.zw;"
- "}",
-
- // FRAGMENT
- "uniform sampler2D uTexMain;"
- "out vec4 FragColor;"
- ""
- "in vec2 aTexCoords;"
- ""
- "void main()"
- "{"
- "vec4 texture_sample = texture( uTexMain, aTexCoords );"
- "FragColor = texture_sample;"
- "}"
- ,
- UNIFORMS({ "uPv", "uTexMain", "uUv", "uPos" })
-)
-
-SHADER_DEFINE( shader_post_darken,
- "layout (location=0) in vec2 a_co;"
- "out vec2 aTexCoords;"
- ""
- "void main()"
- "{"
- "gl_Position = vec4( a_co * 2.0 - 1.0, 0.0, 1.0 );"
- "aTexCoords = a_co;"
- "}",
-
- "uniform sampler2D uTexMain;"
- "out vec4 FragColor;"
- ""
- "in vec2 aTexCoords;"
- ""
- "void main()"
- "{"
- "vec4 texture_sample = texture( uTexMain, aTexCoords );"
- "FragColor = vec4(pow(texture_sample.rgb,vec3(2.2)), 1.0);"
- "}"
- ,
- UNIFORMS({"uTexMain"})
-)
-
-SHADER_DEFINE( shader_post_blur,
- "layout (location=0) in vec2 a_co;"
- "out vec2 aTexCoords;"
- ""
- "void main()"
- "{"
- "gl_Position = vec4( a_co * 2.0 - 1.0, 0.0, 1.0 );"
- "aTexCoords = a_co;"
- "}",
-
- "uniform sampler2D uTexMain;"
- "uniform vec2 uDir;"
- "out vec4 FragColor;"
- ""
- "in vec2 aTexCoords;"
- ""
- "void main()"
- "{"
- "vec4 colour = vec4(0.0);"
-
- "vec2 off1 = vec2(1.411764705882353) * uDir;"
- "vec2 off2 = vec2(3.2941176470588234) * uDir;"
- "vec2 off3 = vec2(5.176470588235294) * uDir;"
- "colour += texture2D( uTexMain, aTexCoords ) * 0.1964825501511404;"
- "colour += texture2D( uTexMain, aTexCoords + off1 ) * 0.2969069646728344;"
- "colour += texture2D( uTexMain, aTexCoords - off1 ) * 0.2969069646728344;"
- "colour += texture2D( uTexMain, aTexCoords + off2 ) * 0.09447039785044732;"
- "colour += texture2D( uTexMain, aTexCoords - off2 ) * 0.09447039785044732;"
- "colour += texture2D( uTexMain, aTexCoords + off3 ) * 0.010381362401148057;"
- "colour += texture2D( uTexMain, aTexCoords - off3 ) * 0.010381362401148057;"
- "FragColor = colour;"
- "}"
- ,
- UNIFORMS({"uTexMain","uDir"})
-)
-
-SHADER_DEFINE( shader_post_comp,
- "layout (location=0) in vec2 a_co;"
- "out vec2 aTexCoords;"
- ""
- "void main()"
- "{"
- "gl_Position = vec4( a_co * 2.0 - 1.0, 0.0, 1.0 );"
- "aTexCoords = a_co;"
- "}",
-
- "uniform sampler2D uTexMain;"
- "uniform sampler2D uTexBloom;"
- "uniform vec2 uComp;" /* x: bloom, y: vignette */
- "out vec4 FragColor;"
- ""
- "in vec2 aTexCoords;"
- ""
- "void main()"
- "{"
- "vec4 texture_sample = texture( uTexMain, aTexCoords );"
- "vec4 bloom_sample = texture( uTexBloom, aTexCoords );"
-
- "vec2 vigCoord = aTexCoords - 0.5;"
- "float vig = pow(1.0 - dot( vigCoord, vigCoord ), 2.0);"
-
- "FragColor = (texture_sample + bloom_sample*0.3*uComp.x)"
- " * max(uComp.y, vig);"
- "}"
- ,
- UNIFORMS({"uTexMain", "uTexBloom", "uComp"})
-)
-
-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 );
- SHADER_INIT( shader_buttons );
- SHADER_INIT( shader_sprite );
- SHADER_INIT( shader_post_darken );
- SHADER_INIT( shader_post_comp );
- SHADER_INIT( shader_post_blur );
-}
-