예제 #1
0
 public override void SetSceneVars(DeviceContext context, Camera camera, Shadowmap shadowmap, ShaderGlobalLights lights)
 {
     VSSceneVars.Vars.ViewProj    = Matrix.Transpose(camera.ViewProjMatrix);
     VSSceneVars.Vars.CameraPos   = new Vector4(camera.Position, 0.0f);
     VSSceneVars.Vars.LightColour = new Vector4(1.0f, 1.0f, 1.0f, lights.HdrIntensity * 2.0f);
     VSSceneVars.Update(context);
     VSSceneVars.SetVSCBuffer(context, 0);
 }
예제 #2
0
 public override void SetSceneVars(DeviceContext context, Camera camera, Shadowmap shadowmap, ShaderGlobalLights lights)
 {
     VSSceneVars.Vars.ViewProj    = Matrix.Transpose(camera.ViewProjMatrix);
     VSSceneVars.Vars.ViewInv     = Matrix.Transpose(camera.ViewInvMatrix);
     VSSceneVars.Vars.ScreenScale = new Vector4(0.5f / camera.Width, 0.5f / camera.Height, camera.Width, camera.Height);
     VSSceneVars.Update(context);
     VSSceneVars.SetVSCBuffer(context, 0);
 }
예제 #3
0
 public override void SetSceneVars(DeviceContext context, Camera camera, Shadowmap shadowmap, ShaderGlobalLights lights)
 {
     VSSceneVars.Vars.ViewProj = Matrix.Transpose(camera.ViewProjMatrix);
     VSSceneVars.Vars.ViewInv  = Matrix.Transpose(camera.ViewInvMatrix);
     VSSceneVars.Vars.CamPos   = camera.Position;
     VSSceneVars.Update(context);
     VSSceneVars.SetVSCBuffer(context, 0);
 }
예제 #4
0
        public override void SetSceneVars(DeviceContext context, Camera camera, Shadowmap shadowmap, ShaderGlobalLights lights)
        {
            uint rendermode    = 0;
            uint rendermodeind = 1;

            SpecularEnable = lights.SpecularEnabled;

            switch (RenderMode)
            {
            case WorldRenderMode.VertexNormals:
                rendermode = 1;
                break;

            case WorldRenderMode.VertexTangents:
                rendermode = 2;
                break;

            case WorldRenderMode.VertexColour:
                rendermode    = 3;
                rendermodeind = (uint)RenderVertexColourIndex;
                break;

            case WorldRenderMode.TextureCoord:
                rendermode    = 4;
                rendermodeind = (uint)RenderTextureCoordIndex;
                break;

            case WorldRenderMode.SingleTexture:
                rendermode = 8;    //direct mode
                break;
            }


            VSSceneVars.Vars.ViewProj   = Matrix.Transpose(camera.ViewProjMatrix);
            VSSceneVars.Vars.WindVector = WindVector;
            VSSceneVars.Update(context);
            VSSceneVars.SetVSCBuffer(context, 0);

            PSSceneVars.Vars.GlobalLights       = lights.Params;
            PSSceneVars.Vars.EnableShadows      = (shadowmap != null) ? 1u : 0u;
            PSSceneVars.Vars.RenderMode         = rendermode;
            PSSceneVars.Vars.RenderModeIndex    = rendermodeind;
            PSSceneVars.Vars.RenderSamplerCoord = (uint)RenderTextureSamplerCoord;
            PSSceneVars.Update(context);
            PSSceneVars.SetPSCBuffer(context, 0);

            if (shadowmap != null)
            {
                shadowmap.SetFinalRenderResources(context);
            }

            if (!InstGlobalVars.Flag) //on the first frame, update the instance globals
            {
                InstGlobalVars.Update(context);
                InstGlobalVars.Flag = true;
            }
        }
예제 #5
0
        public override void SetSceneVars(DeviceContext context, Camera camera, Shadowmap shadowmap, ShaderGlobalLights lights)
        {
            VSSceneVars.Vars.ViewProj = Matrix.Transpose(camera.ViewProjMatrix);
            VSSceneVars.Update(context);
            VSSceneVars.SetVSCBuffer(context, 0);

            PSSceneVars.Vars.GlobalLights = lights.Params;
            PSSceneVars.Update(context);
            PSSceneVars.SetPSCBuffer(context, 0);
        }
예제 #6
0
        public void RenderLights(DeviceContext context, Camera camera, Shadowmap globalShadows, ShaderGlobalLights globalLights)
        {
            //first full-screen directional light pass, for sun/moon
            //discard pixels where scene depth is 0, since nothing was rendered there
            //blend mode: overwrite

            var ps = (MSAASampleCount > 1) ? DirLightMSPS : DirLightPS;

            context.VertexShader.Set(DirLightVS);
            context.PixelShader.Set(ps);

            LightVSVars.Vars.ViewProj  = Matrix.Identity;
            LightVSVars.Vars.CameraPos = Vector4.Zero;
            LightVSVars.Vars.LightType = 0;
            LightVSVars.Vars.IsLOD     = 0;
            LightVSVars.Vars.Pad0      = 0;
            LightVSVars.Vars.Pad1      = 0;
            LightVSVars.Update(context);
            LightVSVars.SetVSCBuffer(context, 0);

            LightPSVars.Vars.GlobalLights       = globalLights.Params;
            LightPSVars.Vars.ViewProjInv        = Matrix.Transpose(camera.ViewProjInvMatrix);
            LightPSVars.Vars.CameraPos          = Vector4.Zero;
            LightPSVars.Vars.EnableShadows      = (globalShadows != null) ? 1u : 0u;
            LightPSVars.Vars.RenderMode         = 0;
            LightPSVars.Vars.RenderModeIndex    = 1;
            LightPSVars.Vars.RenderSamplerCoord = 0;
            LightPSVars.Vars.LightType          = 0;
            LightPSVars.Vars.IsLOD       = 0;
            LightPSVars.Vars.SampleCount = (uint)MSAASampleCount;
            LightPSVars.Vars.SampleMult  = 1.0f / MSAASampleCount;
            LightPSVars.Update(context);
            LightPSVars.SetPSCBuffer(context, 0);

            context.PixelShader.SetShaderResources(0, GBuffers.DepthSRV);
            context.PixelShader.SetShaderResources(2, GBuffers.SRVs);

            if (globalShadows != null)
            {
                globalShadows.SetFinalRenderResources(context);
            }

            context.InputAssembler.InputLayout = LightQuadLayout;
            LightQuad.Draw(context);


            context.VertexShader.Set(null);
            context.PixelShader.Set(null);
            context.PixelShader.SetShaderResources(0, null, null, null);
            context.PixelShader.SetSamplers(0, null, null);
        }
예제 #7
0
        public override void SetSceneVars(DeviceContext context, Camera camera, Shadowmap shadowmap, ShaderGlobalLights lights)
        {
            CloudsLocalVars.Update(context);
            CloudsLocalVars.SetVSCBuffer(context, 0);
            CloudsLocalVars.SetPSCBuffer(context, 0);

            VSSceneVars.Vars.ViewProj = Matrix.Transpose(camera.ViewProjMatrix);
            VSSceneVars.Vars.ViewInv  = Matrix.Transpose(camera.ViewInvMatrix);
            VSSceneVars.Update(context);
            VSSceneVars.SetVSCBuffer(context, 1);

            PSSceneVars.Vars.LightDirection = new Vector4(lights.Params.LightDir, 0.0f);
            PSSceneVars.Vars.EnableHDR      = EnableHDR ? 1u : 0u;
            PSSceneVars.Update(context);
            PSSceneVars.SetPSCBuffer(context, 1);
        }
예제 #8
0
        public override void SetSceneVars(DeviceContext context, Camera camera, Shadowmap shadowmap, ShaderGlobalLights lights)
        {
            switch (mode)
            {
            default:
            case BoundsShaderMode.Sphere:
                VSSphereSceneVars.Vars.ViewProj     = Matrix.Transpose(camera.ViewProjMatrix);
                VSSphereSceneVars.Vars.ViewInv      = Matrix.Transpose(camera.ViewInvMatrix);
                VSSphereSceneVars.Vars.SegmentCount = (float)SegmentCount;
                VSSphereSceneVars.Vars.VertexCount  = (float)VertexCount;
                VSSphereSceneVars.Update(context);
                VSSphereSceneVars.SetVSCBuffer(context, 0);
                break;

            case BoundsShaderMode.Box:
                VSBoxSceneVars.Vars.ViewProj = Matrix.Transpose(camera.ViewProjMatrix);
                VSBoxSceneVars.Update(context);
                VSBoxSceneVars.SetVSCBuffer(context, 0);
                break;
            }
        }
예제 #9
0
        public override void SetSceneVars(DeviceContext context, Camera camera, Shadowmap shadowmap, ShaderGlobalLights lights)
        {
            uint rendermode    = 0;
            uint rendermodeind = 1;

            switch (RenderMode)
            {
            case WorldRenderMode.VertexNormals:
                rendermode = 1;
                break;

            case WorldRenderMode.VertexTangents:
                rendermode = 2;
                break;

            case WorldRenderMode.VertexColour:
                rendermode    = 3;
                rendermodeind = (uint)RenderVertexColourIndex;
                break;

            case WorldRenderMode.TextureCoord:
                rendermode    = 4;
                rendermodeind = (uint)RenderTextureCoordIndex;
                break;

            case WorldRenderMode.SingleTexture:
                switch (RenderTextureSampler)
                {
                case MetaName.DiffuseSampler:
                    rendermode = 5;
                    break;

                case MetaName.BumpSampler:
                    rendermode = 6;
                    break;

                case MetaName.SpecSampler:
                    rendermode = 7;
                    break;

                default:
                    rendermode = 8;
                    break;
                }
                break;
            }


            VSSceneVars.Vars.ViewProj = Matrix.Transpose(camera.ViewProjMatrix);
            VSSceneVars.Update(context);
            VSSceneVars.SetVSCBuffer(context, 0);


            PSSceneVars.Vars.GlobalLights       = lights.Params;
            PSSceneVars.Vars.EnableShadows      = (shadowmap != null) ? 1u : 0u;
            PSSceneVars.Vars.RenderMode         = rendermode;
            PSSceneVars.Vars.RenderModeIndex    = rendermodeind;
            PSSceneVars.Vars.RenderSamplerCoord = (uint)RenderTextureSamplerCoord;
            PSSceneVars.Update(context);
            PSSceneVars.SetPSCBuffer(context, 0);

            if (shadowmap != null)
            {
                shadowmap.SetFinalRenderResources(context);
            }
        }
예제 #10
0
 public abstract void SetSceneVars(DeviceContext context, Camera camera, Shadowmap shadowmap, ShaderGlobalLights lights);
예제 #11
0
 public override void SetSceneVars(DeviceContext context, Camera camera, Shadowmap shadowmap, ShaderGlobalLights lights)
 {
 }
예제 #12
0
        public override void SetSceneVars(DeviceContext context, Camera camera, Shadowmap shadowmap, ShaderGlobalLights lights)
        {
            uint rendermode    = 0;
            uint rendermodeind = 1;

            SpecularEnable = lights.SpecularEnabled;

            switch (RenderMode)
            {
            case WorldRenderMode.VertexNormals:
                rendermode = 1;
                break;

            case WorldRenderMode.VertexTangents:
                rendermode = 2;
                break;

            case WorldRenderMode.VertexColour:
                rendermode    = 3;
                rendermodeind = (uint)RenderVertexColourIndex;
                break;

            case WorldRenderMode.TextureCoord:
                rendermode    = 4;
                rendermodeind = (uint)RenderTextureCoordIndex;
                break;

            case WorldRenderMode.SingleTexture:
                rendermode = 8;    //direct mode
                break;
            }


            float phspd  = 4.0f;
            float phspdi = 1.0f / phspd;
            float phspdh = phspd * 0.5f;
            float t      = (float)(CurrentRealTime - (Math.Floor(CurrentRealTime * 0.001) * 1000.0)) * 1.0f;
            float ta     = t * 2.0f;
            float tb     = ta + (phspdh);
            float t1     = (ta * phspdi - (float)Math.Floor(ta * phspdi)) * phspd;
            float t2     = (tb * phspdi - (float)Math.Floor(tb * phspdi)) * phspd;
            float s1     = ((t1 < phspdh) ? t1 : phspd - t1) * phspdi * 1.0f;
            float s2     = ((t2 < phspdh) ? t2 : phspd - t2) * phspdi * 1.0f;
            //float s1 = ((float)Math.Cos(t1 * phspdi * Math.PI * 2) + 1.0f) * 0.5f;
            //float s2 = ((float)Math.Cos(t2 * phspdi * Math.PI * 2) + 1.0f) * 0.5f;

            float gFlowX = t1 * 0.5f;
            float gFlowY = t2 * 0.5f;
            float gFlowZ = s1;
            float gFlowW = s2;


            Vector2 fogtexMin = new Vector2(-4000.0f, -4000.0f); //aka water quads min/max
            Vector2 fogtexMax = new Vector2(4500.0f, 8000.0f);
            Vector2 fogtexInv = 1.0f / (fogtexMax - fogtexMin);


            bool usewaterbumps = (waterbump != null) && (waterbump.ShaderResourceView != null) && (waterbump2 != null) && (waterbump2.ShaderResourceView != null);
            bool usefogtex     = (waterfog != null) && (waterfog.ShaderResourceView != null);

            VSSceneVars.Vars.ViewProj    = Matrix.Transpose(camera.ViewProjMatrix);
            VSSceneVars.Vars.WaterVector = Vector4.Zero;
            VSSceneVars.Vars.ScaledTime  = t * 0.1f;
            VSSceneVars.Update(context);
            VSSceneVars.SetVSCBuffer(context, 0);

            PSSceneVars.Vars.GlobalLights       = lights.Params;
            PSSceneVars.Vars.EnableShadows      = (shadowmap != null) ? 1u : 0u;
            PSSceneVars.Vars.RenderMode         = rendermode;
            PSSceneVars.Vars.RenderModeIndex    = rendermodeind;
            PSSceneVars.Vars.RenderSamplerCoord = (uint)RenderTextureSamplerCoord;
            PSSceneVars.Vars.EnableWaterbumps   = usewaterbumps ? 1u : 0u;
            PSSceneVars.Vars.EnableFogtex       = usefogtex ? 1u : 0u;
            PSSceneVars.Vars.gFlowParams        = new Vector4(gFlowX, gFlowY, gFlowZ, gFlowW);
            PSSceneVars.Vars.CameraPos          = new Vector4(camera.Position, 0.0f);
            PSSceneVars.Vars.WaterFogParams     = new Vector4(fogtexMin, fogtexInv.X, fogtexInv.Y);
            PSSceneVars.Update(context);
            PSSceneVars.SetPSCBuffer(context, 0);

            if (shadowmap != null)
            {
                shadowmap.SetFinalRenderResources(context);
            }
            if (usewaterbumps)
            {
                context.PixelShader.SetShaderResource(4, waterbump.ShaderResourceView);
                context.PixelShader.SetShaderResource(5, waterbump2.ShaderResourceView);
            }
            if (usefogtex)
            {
                context.PixelShader.SetShaderResource(6, waterfog.ShaderResourceView);
            }
        }