コード例 #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);
        }
コード例 #2
0
ファイル: Render.cs プロジェクト: zdimension/FreeRaider
        public void RenderDynamicEntitySkin(LitShaderDescription shader, Entity ent, Matrix4 mvMatrix, Matrix4 pMatrix)
        {
            GL.UniformMatrix4(shader.Projection, false, ref pMatrix);

            for (var i = 0; i < ent.Bf.BoneTags.Count; i++)
            {
                var mat0 = mvMatrix * ent.Bt.BtBody[i].GetWorldTransform();
                var tr1 = new Matrix4();
                // Calculate parent transform
                var btag = ent.Bf.BoneTags[i];
                var foundParentTransform = false;
                for (var j = 0; j < ent.Bf.BoneTags.Count; j++)
                {
                    if(ent.Bf.BoneTags[i] == btag.Parent)
                    {
                        tr1 = ent.Bt.BtBody[j].GetWorldTransform();
                        foundParentTransform = true;
                        break;
                    }
                }
                if (!foundParentTransform)
                    tr1 = (Matrix4) ent.Transform;

                var translate = new Transform();
                translate.SetIdentity();
                translate.Origin += btag.Offset;

                var secondTransform = tr1.MultiplyByTransform(translate);
                var mat1 = mvMatrix * secondTransform;

                var transforms = new float[32];
                unsafe
                {
                    Array.Copy(Helper.GetArrayFromPointer(&mat0.Row0.X, 16), transforms, 16);
                    Array.Copy(Helper.GetArrayFromPointer(&mat1.Row0.X, 16), 0, transforms, 16, 16);
                }
                GL.UniformMatrix4(shader.ModelView, 2, false, transforms);

                if (btag.MeshSkin != null)
                {
                    RenderMesh(btag.MeshSkin);
                }
            }
        }
コード例 #3
0
ファイル: Render.cs プロジェクト: zdimension/FreeRaider
        public void RenderSkeletalModelSkin(LitShaderDescription shader, Entity ent, Matrix4 mvMatrix, Matrix4 pMatrix)
        {
            GL.UniformMatrix4(shader.Projection, false, ref pMatrix);

            foreach (var btag in ent.Bf.BoneTags)
            {
                var transforms = new float[32];
                var mvTransforms = mvMatrix.MultiplyByTransform(btag.FullTransform);
                unsafe
                {
                    Array.Copy(Helper.GetArrayFromPointer(&mvTransforms.Row0.X, 16), transforms, 16);
                }

                // Calculate parent transform
                var parentTransform = btag.Parent == null ? ent.Transform : btag.Parent.FullTransform;

                var translate = new Transform();
                translate.SetIdentity();
                translate.Origin += btag.Offset;

                var secondTransform = parentTransform * translate;

                var mvTransforms2 = mvMatrix.MultiplyByTransform(secondTransform);
                unsafe
                {
                    Array.Copy(Helper.GetArrayFromPointer(&mvTransforms2.Row0.X, 16), 0, transforms, 16, 16);
                }
                GL.UniformMatrix4(shader.ModelView, 2, false, transforms);

                if(btag.MeshSkin != null)
                {
                    RenderMesh(btag.MeshSkin);
                }
            }
        }
コード例 #4
0
ファイル: Render.cs プロジェクト: zdimension/FreeRaider
        public void RenderDynamicEntity(LitShaderDescription shader, Entity entity, Matrix4 modelViewMatrix,
            Matrix4 modelViewProjectionMatrix)
        {
            for (var i = 0; i < entity.Bf.BoneTags.Count; i++)
            {
                var btag = entity.Bf.BoneTags[i];

                var tr = entity.Bt.BtBody[i].GetWorldTransform();
                var mvTransform = modelViewMatrix * tr;

                GL.UniformMatrix4(shader.ModelView, false, ref mvTransform);

                var mvpTransform = modelViewProjectionMatrix * tr;
                GL.UniformMatrix4(shader.ModelViewProjection, false, ref mvpTransform);

                RenderMesh(btag.MeshBase);
                if(btag.MeshSlot != null)
                {
                    RenderMesh(btag.MeshSlot);
                }
            }
        }
コード例 #5
0
ファイル: Render.cs プロジェクト: zdimension/FreeRaider
        public void RenderSkeletalModel(LitShaderDescription shader, SSBoneFrame bframe, Matrix4 mvMatrix,
            Matrix4 mvpMatrix)
        {
            foreach (var btag in bframe.BoneTags)
            {
                var mvTransform = mvMatrix.MultiplyByTransform(btag.FullTransform);
                GL.UniformMatrix4(shader.ModelView, false, ref mvTransform);

                var mvpTransform = mvpMatrix.MultiplyByTransform(btag.FullTransform);
                GL.UniformMatrix4(shader.ModelViewProjection, false, ref mvpTransform);

                RenderMesh(btag.MeshBase);
                if (btag.MeshSlot != null)
                {
                    RenderMesh(btag.MeshSlot);
                }
            }
        }