Exemplo n.º 1
0
        public ShaderManager()
        {
            var staticMeshVsh = new ShaderStage(ShaderType.VertexShader, "shaders/static_mesh.vsh");
            var staticMeshFsh = new ShaderStage(ShaderType.FragmentShader, "shaders/static_mesh.fsh");
            // Color mult prog
            staticMeshShader = new UnlitTintedShaderDescription(staticMeshVsh, staticMeshFsh);

            // Room prog
            var roomFragmentShader = new ShaderStage(ShaderType.FragmentShader, "shaders/room.fsh");
            for (var isWater = 0; isWater < 2; isWater++)
            {
                for (var isFlicker = 0; isFlicker < 2; isFlicker++)
                {
                    var stream =
                        "#define IS_WATER " + isWater + "\n" +
                        "#define IS_FLICKER " + isFlicker + "\n";

                    var roomVsh = new ShaderStage(ShaderType.VertexShader, "shaders/room.vsh", stream);
                    roomShaders[isWater][isFlicker] = new UnlitTintedShaderDescription(roomVsh, roomFragmentShader);
                }
            }

            // Entity prog
            var entityVertexShader = new ShaderStage(ShaderType.VertexShader, "shaders/entity.vsh");
            var entitySkinVertexShader = new ShaderStage(ShaderType.VertexShader, "shaders/entity_skin.vsh");
            for (var i = 0; i < MAX_NUM_LIGHTS; i++)
            {
                var stream = "#define NUMBER_OF_LIGHTS " + i + "\n";

                var fragment = new ShaderStage(ShaderType.FragmentShader, "shaders/entity.fsh", stream);
                entityShader[i][0] = new LitShaderDescription(entityVertexShader, fragment);
                entityShader[i][1] = new LitShaderDescription(entitySkinVertexShader, fragment);
            }

            // GUI prog
            var guiVertexShader = new ShaderStage(ShaderType.VertexShader, "shaders/gui.vsh");
            var guiFsh = new ShaderStage(ShaderType.FragmentShader, "shaders/gui.fsh");
            gui = new GuiShaderDescription(guiVertexShader, guiFsh);

            var guiTexFsh = new ShaderStage(ShaderType.FragmentShader, "shaders/gui_tex.fsh");
            guiTextured = new GuiShaderDescription(guiVertexShader, guiTexFsh);

            var textVsh = new ShaderStage(ShaderType.VertexShader, "shaders/text.vsh");
            var textFsh = new ShaderStage(ShaderType.FragmentShader, "shaders/text.fsh");
            text = new TextShaderDescription(textVsh, textFsh);

            var spriteVsh = new ShaderStage(ShaderType.VertexShader, "shaders/sprite.vsh");
            var spriteFsh = new ShaderStage(ShaderType.FragmentShader, "shaders/sprite.fsh");
            sprites = new SpriteShaderDescription(spriteVsh, spriteFsh);

            var stencilVsh = new ShaderStage(ShaderType.VertexShader, "shaders/stencil.vsh");
            var stencilFsh = new ShaderStage(ShaderType.FragmentShader, "shaders/stencil.fsh");
            stencil = new LitShaderDescription(stencilVsh, stencilFsh);

            var debugVsh = new ShaderStage(ShaderType.VertexShader, "shaders/debuglines.vsh");
            var debugFsh = new ShaderStage(ShaderType.FragmentShader, "shaders/debuglines.fsh");
            debugLine = new UnlitTintedShaderDescription(debugVsh, debugFsh);
        }
Exemplo n.º 2
0
        public GuiShaderDescription(ShaderStage vertex, ShaderStage fragment) : base(vertex, fragment)
        {
            Offset = GL.GetUniformLocation(Program, "offset");
            Factor = GL.GetUniformLocation(Program, "factor");
            GL.BindAttribLocation(Program, (int)VertexAttribs.Position, "position");
            GL.BindAttribLocation(Program, (int)VertexAttribs.Color, "color");
            GL.LinkProgram(Program);
            int isLinked;
            GL.GetProgram(Program, GetProgramParameterName.LinkStatus, out isLinked);
            StaticFuncs.Assert(isLinked != 0);

            GLUtil.CheckOpenGLError();
            GLUtil.PrintShaderInfoLog(Program);
        }
Exemplo n.º 3
0
        public ShaderDescription(ShaderStage vertex, ShaderStage fragment)
        {
            Program = GL.CreateProgram();
            GL.AttachShader(Program, vertex.Shader);
            GL.AttachShader(Program, fragment.Shader);
            GL.LinkProgram(Program);
            int isLinked;
            GL.GetProgram(Program, GetProgramParameterName.LinkStatus, out isLinked);
            StaticFuncs.Assert(isLinked != 0);

            GLUtil.CheckOpenGLError();
            GLUtil.PrintShaderInfoLog(Program);

            Sampler = GL.GetUniformLocation(Program, "color_map");
        }
Exemplo n.º 4
0
 public UnlitTintedShaderDescription(ShaderStage vertex, ShaderStage fragment) : base(vertex, fragment)
 {
     CurrentTick = GL.GetUniformLocation(Program, "fCurrentTick");
     TintMult = GL.GetUniformLocation(Program, "tintMult");
 }
Exemplo n.º 5
0
 public LitShaderDescription(ShaderStage vertex, ShaderStage fragment) : base(vertex, fragment)
 {
     ModelView = GL.GetUniformLocation(Program, "modelView");
     Projection = GL.GetUniformLocation(Program, "projection");
     NumberOfLights = GL.GetUniformLocation(Program, "number_of_lights");
     LightPosition = GL.GetUniformLocation(Program, "light_position");
     LightColor = GL.GetUniformLocation(Program, "light_color");
     LightInnerRadius = GL.GetUniformLocation(Program, "light_innerRadius");
     LightOuterRadius = GL.GetUniformLocation(Program, "light_outerRadius");
     LightAmbient = GL.GetUniformLocation(Program, "light_ambient");
 }
Exemplo n.º 6
0
        public UnlitShaderDescription(ShaderStage vertex, ShaderStage fragment) : base(vertex, fragment)
        {
            GL.BindAttribLocation(Program, (int)VertexAttribs.Position, "position");
            GL.BindAttribLocation(Program, (int)VertexAttribs.Color, "color");
            GL.BindAttribLocation(Program, (int)VertexAttribs.TexCoord, "texCoord");
            GL.BindAttribLocation(Program, (int)VertexAttribs.Normal, "normal");
            GL.BindAttribLocation(Program, (int)VertexAttribs.MatrixIndex, "matrixIndex");
            GL.LinkProgram(Program);
            int isLinked;
            GL.GetProgram(Program, GetProgramParameterName.LinkStatus, out isLinked);
            StaticFuncs.Assert(isLinked != 0);

            GLUtil.CheckOpenGLError();
            GLUtil.PrintShaderInfoLog(Program);

            ModelViewProjection = GL.GetUniformLocation(Program, "modelViewProjection");
        }
Exemplo n.º 7
0
        public TextShaderDescription(ShaderStage vertex, ShaderStage fragment) : base(vertex, fragment)
        {
            GL.BindAttribLocation(Program, (int)VertexAttribs.Position, "position");
            GL.BindAttribLocation(Program, (int)VertexAttribs.Color, "color");
            GL.BindAttribLocation(Program, (int)VertexAttribs.TexCoord, "texCoord");
            GL.LinkProgram(Program);
            int isLinked;
            GL.GetProgram(Program, GetProgramParameterName.LinkStatus, out isLinked);
            StaticFuncs.Assert(isLinked != 0);

            GLUtil.CheckOpenGLError();
            GLUtil.PrintShaderInfoLog(Program);

            ScreenSize = GL.GetUniformLocation(Program, "screenSize");
        }
Exemplo n.º 8
0
        public SpriteShaderDescription(ShaderStage vertex, ShaderStage fragment) : base(vertex, fragment)
        {
            ModelView = GL.GetUniformLocation(Program, "modelView");
            Projection = GL.GetUniformLocation(Program, "projection");
            GL.BindAttribLocation(Program, (int)VertexAttribs.Position, "position");
            GL.BindAttribLocation(Program, (int)VertexAttribs.CornerOffset, "cornerOffset");
            GL.BindAttribLocation(Program, (int)VertexAttribs.TexCoord, "texCoord");
            GL.LinkProgram(Program);
            int isLinked;
            GL.GetProgram(Program, GetProgramParameterName.LinkStatus, out isLinked);
            StaticFuncs.Assert(isLinked != 0);

            GLUtil.CheckOpenGLError();
            GLUtil.PrintShaderInfoLog(Program);
        }