Ejemplo n.º 1
0
        public virtual void InitCBuffersFrame(DeviceContext context, Camera camera, WorldSettings settings)
        {
            var cameraBuffer = new DCameraBuffer()
            {
                cameraPosition = camera.Position,
                padding        = 0.0f
            };

            ConstantBufferFactory.UpdateVertexBuffer(context, ConstantCameraBuffer, 1, cameraBuffer);

            if (previousLighting == null || !previousLighting.Equals(settings.Lighting))
            {
                LightBuffer lightbuffer = new LightBuffer()
                {
                    ambientColor   = settings.Lighting.AmbientColor,
                    diffuseColor   = settings.Lighting.DiffuseColour,
                    LightDirection = settings.Lighting.Direction,
                    specularColor  = settings.Lighting.SpecularColor,
                    specularPower  = settings.Lighting.SpecularPower
                };
                previousLighting = settings.Lighting;
                ConstantBufferFactory.UpdatePixelBuffer(context, ConstantLightBuffer, 0, lightbuffer);
            }
        }
Ejemplo n.º 2
0
        public override void InitCBuffersFrame(DeviceContext deviceContext, Camera camera, LightClass light)
        {
            DataStream mappedResource;

            #region Constant Camera Buffer
            deviceContext.MapSubresource(ConstantCameraBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);
            var cameraBuffer = new DCameraBuffer()
            {
                cameraPosition = camera.Position,
                padding        = 0.0f
            };
            mappedResource.Write(cameraBuffer);
            deviceContext.UnmapSubresource(ConstantCameraBuffer, 0);
            int bufferSlotNumber = 1;
            deviceContext.VertexShader.SetConstantBuffer(bufferSlotNumber, ConstantCameraBuffer);
            #endregion
            #region Constant Light Buffer
            if (lighting == null || !lighting.Equals(light))
            {
                deviceContext.MapSubresource(ConstantLightBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);
                LightBuffer lightbuffer = new LightBuffer()
                {
                    ambientColor   = light.AmbientColor,
                    diffuseColor   = light.DiffuseColour,
                    LightDirection = light.Direction,
                    specularColor  = light.SpecularColor,
                    specularPower  = light.SpecularPower
                };
                mappedResource.Write(lightbuffer);
                deviceContext.UnmapSubresource(ConstantLightBuffer, 0);
                bufferSlotNumber = 0;
                deviceContext.PixelShader.SetConstantBuffer(bufferSlotNumber, ConstantLightBuffer);
                lighting = light;
            }
            #endregion
        }