Example #1
0
        protected override void ConstructFragmentShader(ShaderBuilder frag)
        {
            base.ConstructFragmentShader(frag);

            frag.AddUniform(ShaderVarType.Sampler2DArray, "tiles");
            frag.AddUniform(ShaderVarType.Sampler2D, "bloodmap");
            frag.Logic = @"
                void main(void)
                {
                    vec4 clr = texture2DArray(tiles, var_tex);
                    if (clr.a < 1.0)
                        discard;

                    vec2 blood_tex = vec2(
                        floor(var_blood_tex.x) / world_size.x,
                        floor(var_blood_tex.y) / world_size.y
                    ) / 8.0;

                    float blood = floor(var_blood * 8.0) / 8.0;

                    if (blood > 0.0) {
                        blood = floor(blood * texture2D(bloodmap, blood_tex).a * 5.0) / 4.0;
                        clr = clr * (2.0 - blood) * 0.5 + vec4(0.2, 0.0, 0.0, 0.0) * blood;
                    }
   
                    out_colour = vec4(clr.rgb * var_shade, 1.0);
                }
            ";
        }
Example #2
0
        protected override void ConstructFragmentShader(ShaderBuilder frag)
        {
            base.ConstructVertexShader(frag);

            frag.AddUniform(ShaderVarType.Mat4, "proj");
            frag.AddUniform(ShaderVarType.Mat4, "view");
            frag.AddUniform(ShaderVarType.Vec3, "camera");
        }
Example #3
0
        protected override void ConstructVertexShader(ShaderBuilder vert)
        {
            base.ConstructVertexShader(vert);

            vert.AddUniform(ShaderVarType.Mat4, "proj");
            vert.AddUniform(ShaderVarType.Mat4, "view");
            vert.AddUniform(ShaderVarType.Vec3, "camera");
        }
Example #4
0
        protected override void ConstructFragmentShader(ShaderBuilder frag)
        {
            base.ConstructFragmentShader(frag);

            frag.AddUniform(ShaderVarType.Vec3, "sun");
            frag.AddUniform(ShaderVarType.Float, "time");
            frag.AddUniform(ShaderVarType.Vec4, "light_model");
            frag.AddUniform(ShaderVarType.Vec3, "colour");
            frag.AddUniform(ShaderVarType.SamplerCube, "skybox");
        }
Example #5
0
        protected override void ConstructFragmentShader(ShaderBuilder frag)
        {
            base.ConstructFragmentShader(frag);

            frag.AddUniform(ShaderVarType.SamplerCube, "skybox");
            frag.AddUniform(ShaderVarType.Vec3, "sun");
            frag.AddUniform(ShaderVarType.Float, "time");
            frag.Logic = SunFragSource + @"
                void main(void)
                {
                    vec3 sky = textureCube(skybox, var_texcoord).rgb;
                    out_colour = vec4(sky + (vec3(1, 1, 1) - sky) * getSun(var_texcoord), 1);
                }
            ";
        }
        protected override void ConstructVertexShader(ShaderBuilder vert)
        {
            base.ConstructVertexShader(vert);

            vert.AddUniform(ShaderVarType.Vec4, "body");
            vert.AddAttribute(ShaderVarType.Vec2, "in_vertex");
            vert.AddVarying(ShaderVarType.Vec3, "var_position");
            vert.Logic = @"
                void main(void)
                {
                    float r = body.w;
                    vec3 cam = camera - body.xyz;
                    float dist = length(cam);
                    float hyp = sqrt(dist * dist - r * r);
                    float ang = atan(r / hyp);
                    float opp = hyp * sin(ang);
                    float dif = sqrt(r * r - opp * opp);

                    vec3 center = normalize(cam) * dif;
                    vec3 up = normalize(cross(cam, (view * vec4(0, 0, 1, 0)).xyz)) * opp;
                    vec3 right = normalize(cross(cam, up)) * opp;

                    var_position = vec3(center + in_vertex.x * right + in_vertex.y * up) / r;

                    gl_Position = proj * view * vec4(body.xyz + center + in_vertex.x * right + in_vertex.y * up, 1);
                }
            ";
        }
Example #7
0
        protected override void ConstructVertexShader(ShaderBuilder vert)
        {
            base.ConstructVertexShader(vert);

            vert.AddUniform(ShaderVarType.Mat4, "mdl_matrix");
            vert.AddAttribute(ShaderVarType.Vec3, "in_position");
            vert.AddAttribute(ShaderVarType.Vec3, "in_texture");
            vert.AddAttribute(ShaderVarType.Vec3, "in_normal");
            vert.AddVarying(ShaderVarType.Float, "var_shade");
            vert.AddVarying(ShaderVarType.Vec3, "var_texture");
            vert.Logic = @"
                void main(void)
                {
                    var_texture = in_texture;

                    const vec3 sun_dir = normalize(vec3(1.0, -2.0, 0.0));

                    var_shade = 0.75 + abs(dot(sun_dir, (mdl_matrix * vec4(in_normal, 0.0)).xyz)) * 0.25;

                    vec3 world_pos = (mdl_matrix * vec4(in_position, 1.0)).xyz;

                    gl_Position = proj * view * vec4(
                        world_pos.x + world_offset.x,
                        world_pos.y,
                        world_pos.z + world_offset.y,
                        1.0
                    );
                }
            ";
        }
        protected override void ConstructFragmentShader(ShaderBuilder frag)
        {
            base.ConstructFragmentShader(frag);

            frag.AddUniform(ShaderVarType.Vec4, "body");
            frag.Logic = GetRenderFuncSource() + @"
                void main(void)
                {
                    float r = body.w;
                    vec3 cam = camera - body.xyz;
                    float len2 = dot(var_position, var_position);

                    if (len2 > 1) discard;

                    vec3 l = normalize(cam / r - var_position);

                    float b = dot(l, var_position);
                    float d = -b + sqrt(b * b - len2 + 1);

                    vec3 pos = (var_position + l * d) * r;
                    vec4 fin = proj * view * vec4(pos + body.xyz, 1);

                    gl_FragDepth = (fin.z / fin.w + 1) / 2;

                    out_colour = render(pos, cam);
                }
            ";
        }
Example #9
0
        protected override void ConstructFragmentShader(ShaderBuilder frag)
        {
            base.ConstructFragmentShader(frag);

            frag.AddUniform(ShaderVarType.Sampler2D, "frame");
            frag.Logic = @"
                void main(void)
                {
                    gl_FragColor = texture2D(frame, var_texcoord);
                }
            ";
        }
        public static Shader CreateDefaultShader()
        {
            var sb = new ShaderBuilder(VertexDeclaration);

            var combinedMatrix = sb.AddUniform(CombinedMatrixUniformName, "mat4");
            var texture        = sb.AddUniform(TextureUniformName, "sampler2D");

            var color        = sb.AddVarying("vec4");
            var textureCoord = sb.AddVarying("vec2");

            sb.VertexShader = new Sequence(
                new Assign(color, sb.VertexDeclaration.GetAttribute(AttributeUsage.Color)),
                new Assign(textureCoord, sb.VertexDeclaration.GetAttribute(AttributeUsage.DiffuseMapCoord)),
                new Assign(sb.GlPosition, () => $"{combinedMatrix.Ref} * vec4({sb.VertexDeclaration.GetAttribute(AttributeUsage.Position).Name}, 0, 1)")
                );
            sb.FragmentShader = new Sequence(
                new Assign(sb.GlFragColor, () => $"{color.Ref} * texture2D({texture.Ref}, {textureCoord.Ref})")
                );

            return(sb.Build());
        }
Example #11
0
        protected override void ConstructFragmentShader(ShaderBuilder frag)
        {
            base.ConstructFragmentShader(frag);

            frag.AddUniform(ShaderVarType.Vec4, "colour");
            frag.Logic = @"
                void main(void)
                {
                    out_colour = colour;
                }
            ";
        }
Example #12
0
        protected override void ConstructFragmentShader(ShaderBuilder frag)
        {
            base.ConstructFragmentShader(frag);

            frag.AddUniform(ShaderVarType.Sampler2DArray, "ents");
            frag.Logic = @"
                void main(void)
                {
                    out_colour = texture2DArray(ents, var_texture);
                    if(out_colour.a < 0.5) discard;
                }
            ";
        }
Example #13
0
        protected override void ConstructVertexShader(ShaderBuilder vert)
        {
            base.ConstructVertexShader(vert);

            vert.AddUniform(ShaderVarType.Vec2, "scale");
            vert.AddUniform(ShaderVarType.Vec3, "position");
            vert.AddUniform(ShaderVarType.Vec2, "size");
            vert.AddUniform(ShaderVarType.Float, "texture");
            vert.AddAttribute(ShaderVarType.Vec3, "in_vertex");
            vert.AddVarying(ShaderVarType.Vec3, "var_texture");
            vert.Logic = @"
                void main(void)
                {
                    switch(int(in_vertex.z))
                    {
                        case 0:
                            var_texture = vec3(0.0, 0.0, texture); break;
                        case 1:
                            var_texture = vec3(size.x, 0.0, texture); break;
                        case 2:
                            var_texture = vec3(0.0, size.y, texture); break;
                        case 3:
                            var_texture = vec3(size.x, size.y, texture); break;
                    }

                    const float yscale = 2.0 / sqrt(3.0);

                    gl_Position = proj * view * vec4(
                        position.x + world_offset.x,
                        (position.y + in_vertex.y * size.y) * yscale,
                        position.z + world_offset.y,
                        1.0
                    ) + vec4(in_vertex.x * scale.x * size.x, 0.0, 0.0, 0.0);
                }
            ";
        }
Example #14
0
        public static Shader CreateDefaultShader()
        {
            var sb = new ShaderBuilder(VertexDeclaration);

            var combinedMatrix = sb.AddUniform(CombinedMatrixUniformName, "mat4");
            var color          = sb.AddVarying("vec4");

            sb.VertexShader = new Sequence(
                new Assign(color, sb.VertexDeclaration.GetAttribute(AttributeUsage.Color)),
                new Assign(sb.GlPosition, () => $"{combinedMatrix.Ref} * vec4({sb.VertexDeclaration.GetAttribute(AttributeUsage.Position).Name}, 1)")
                );
            sb.FragmentShader = new Sequence(
                new Assign(sb.GlFragColor, () => $"{color.Ref}")
                );

            return(sb.Build());
        }
Example #15
0
        protected override void ConstructFragmentShader(ShaderBuilder frag)
        {
            base.ConstructFragmentShader(frag);

            frag.AddUniform(ShaderVarType.Sampler2D, "sprite");
            frag.Logic = @"
                void main(void)
                {
                    vec4 clr = texture2D(sprite, var_texture) * var_colour;

                    if (clr.a != 0.0) {
                        out_colour = clr.rgba;
                    } else {
                        discard;
                    }
                }
            ";
        }
Example #16
0
        protected override void ConstructFragmentShader(ShaderBuilder frag)
        {
            base.ConstructFragmentShader(frag);

            frag.AddUniform(ShaderVarType.Sampler2D, "sprite");
            frag.Logic = @"
                void main(void)
                {
                    vec4 clr = texture2D(sprite, var_texture) * var_colour;

                    if (clr.a != 0.0) {
                        out_colour = clr.rgba;
                    } else {
                        discard;
                    }
                }
            ";
        }
Example #17
0
        protected override void ConstructFragmentShader(ShaderBuilder frag)
        {
            frag.AddUniform(ShaderVarType.Vec4, "color");

            base.ConstructFragmentShader(frag);
        }