Example #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);
        }
Example #2
0
        public void RenderBSPBackToFront(BlendingMode currentTransparency, BSPNode root,
            UnlitTintedShaderDescription shader)
        {
            var d = root.Plane.Distance(EngineCamera.Position);

            if (d >= 0)
            {
                if (root.Back != null)
                {
                    RenderBSPBackToFront(currentTransparency, root.Back, shader);
                }

                foreach (var p in root.PolygonsBack)
                {
                    RenderPolygonTransparency(currentTransparency, p, shader);
                }
                foreach (var p in root.PolygonsFront)
                {
                    RenderPolygonTransparency(currentTransparency, p, shader);
                }

                if (root.Front != null)
                {
                    RenderBSPBackToFront(currentTransparency, root.Front, shader);
                }
            }
            else
            {
                if (root.Front != null)
                {
                    RenderBSPBackToFront(currentTransparency, root.Front, shader);
                }

                foreach (var p in root.PolygonsFront)
                {
                    RenderPolygonTransparency(currentTransparency, p, shader);
                }
                foreach (var p in root.PolygonsBack)
                {
                    RenderPolygonTransparency(currentTransparency, p, shader);
                }

                if (root.Back != null)
                {
                    RenderBSPBackToFront(currentTransparency, root.Back, shader);
                }
            }
        }
Example #3
0
        public void RenderPolygonTransparency(BlendingMode currentTransparency, BSPFaceRef bspRef,
            UnlitTintedShaderDescription shader)
        {
            // Blending mode switcher.
            // Note that modes above 2 aren't explicitly used in TR textures, only for
            // internal particle processing. Theoretically it's still possible to use
            // them if you will force type via TRTextur utility.
            var refe = bspRef.Polygon;
            var p = refe.Polygon;
            if(currentTransparency != p.BlendMode)
            {
                currentTransparency = p.BlendMode;
                switch (p.BlendMode)
                {
                    case BlendingMode.Multiply: // Classic PC alpha
                        GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.One);
                        break;

                    case BlendingMode.InvertSrc: // Inversion by src (PS darkness) - SAME AS IN TR3-TR5
                        GL.BlendFunc(BlendingFactorSrc.Zero, BlendingFactorDest.OneMinusSrcAlpha);
                        break;

                    case BlendingMode.InvertDst: // Inversion by dest
                        GL.BlendFunc(BlendingFactorSrc.OneMinusSrcColor, BlendingFactorDest.OneMinusSrcAlpha);
                        break;

                    case BlendingMode.Screen: // Screen (smoke, etc.)
                        GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.OneMinusSrcAlpha);
                        break;

                    case BlendingMode.AnimatedTexture:
                        GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.Zero);
                        break;
                }
            }

            var mvp = Camera.GLViewProjMat.MultiplyByTransform(bspRef.Transform);

            GL.UniformMatrix4(shader.ModelViewProjection, false, ref mvp);

            refe.UsedVertexArray.Bind();
            GL.BindTexture(TextureTarget.Texture2D, World.Textures[p.TexIndex]);

            GL.DrawElements(PrimitiveType.Triangles, (int)refe.Count, DrawElementsType.UnsignedInt, (int)(sizeof(uint) * refe.FirstIndex));
        }