public GeometryShader() { ShaderBuilder vert = new ShaderBuilder(ShaderType.VertexShader, false); vert.AddUniform(ShaderVarType.Mat4, "view_matrix"); vert.AddAttribute(ShaderVarType.Vec3, "in_position"); vert.AddAttribute(ShaderVarType.Vec2, "in_tex"); vert.AddVarying(ShaderVarType.Float, "var_shade"); vert.AddVarying(ShaderVarType.Vec3, "var_tex"); vert.Logic = @" float roots[ 4 ] = float[]( 0.0, 1.0, 0.70710678118654752440084436210485, 0.57735026918962576450914878050196 ); vec3 sun_dir = normalize( vec3( 0.6, -0.7, 0.4 ) ); void main( void ) { int faceData = int( in_tex.x / 289 ); int texPosIndex = int( in_tex.x ) % 289; float size = float( faceData / 27 ); int face = faceData % 27; vec3 norm = normalize( vec3( face % 3 - 1, ( face / 3 ) % 3 - 1, ( face / 9 ) % 3 - 1 ) ); var_shade = dot( norm, sun_dir ) * 0.25 + 0.75; vec2 texPos = vec2( texPosIndex % 17, texPosIndex / 17 ); var_tex = vec3( texPos / 16.0 * size, in_tex.y ); gl_Position = view_matrix * vec4( in_position, 1.0 ); } "; ShaderBuilder frag = new ShaderBuilder(ShaderType.FragmentShader, false); frag.AddUniform(ShaderVarType.Sampler2DArray, "tilemap"); frag.AddVarying(ShaderVarType.Float, "var_shade"); frag.AddVarying(ShaderVarType.Vec3, "var_tex"); frag.Logic = @" void main( void ) { out_frag_colour = texture2DArray( tilemap, var_tex ) * vec4( var_shade, var_shade, var_shade, 1.0 ); } "; VertexSource = vert.Generate(GL3); FragmentSource = frag.Generate(GL3); BeginMode = BeginMode.Triangles; CameraPosition = new Vector3(); CameraRotation = new Vector2(); }
public SpriteShader() { ShaderBuilder vert = new ShaderBuilder(ShaderType.VertexShader, true); vert.AddAttribute(ShaderVarType.Vec2, "in_position"); vert.AddAttribute(ShaderVarType.Vec2, "in_texture"); vert.AddAttribute(ShaderVarType.Vec4, "in_colour"); vert.AddVarying(ShaderVarType.Vec2, "var_texture"); vert.AddVarying(ShaderVarType.Vec4, "var_colour"); vert.Logic = @" void main( void ) { var_texture = in_texture; var_colour = in_colour; gl_Position = in_position; } "; ShaderBuilder frag = new ShaderBuilder(ShaderType.FragmentShader, true); frag.AddUniform(ShaderVarType.Sampler2D, "texture0"); frag.AddVarying(ShaderVarType.Vec2, "var_texture"); frag.AddVarying(ShaderVarType.Vec4, "var_colour"); frag.Logic = @" void main( void ) { vec4 clr = texture2D( texture0, var_texture ) * var_colour; if( clr.a != 0.0 ) out_frag_colour = vec4( clr.rgba ); else discard; } "; VertexSource = vert.Generate(GL3); FragmentSource = frag.Generate(GL3); BeginMode = BeginMode.Quads; }
public SpriteShader() { ShaderBuilder vert = new ShaderBuilder( ShaderType.VertexShader, true ); vert.AddAttribute( ShaderVarType.Vec2, "in_position" ); vert.AddAttribute( ShaderVarType.Vec2, "in_texture" ); vert.AddAttribute( ShaderVarType.Vec4, "in_colour" ); vert.AddVarying( ShaderVarType.Vec2, "var_texture" ); vert.AddVarying( ShaderVarType.Vec4, "var_colour" ); vert.Logic = @" void main( void ) { var_texture = in_texture; var_colour = in_colour; gl_Position = in_position; } "; ShaderBuilder frag = new ShaderBuilder( ShaderType.FragmentShader, true ); frag.AddUniform( ShaderVarType.Sampler2D, "texture0" ); frag.AddVarying( ShaderVarType.Vec2, "var_texture" ); frag.AddVarying( ShaderVarType.Vec4, "var_colour" ); frag.Logic = @" void main( void ) { vec4 clr = texture2D( texture0, var_texture ) * var_colour; if( clr.a != 0.0 ) out_frag_colour = vec4( clr.rgba ); else discard; } "; VertexSource = vert.Generate( GL3 ); FragmentSource = frag.Generate( GL3 ); BeginMode = BeginMode.Quads; }