private bool SetShaderParameters(DeviceContext deviceContext, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix)
        {
            try
            {
                worldMatrix.Transpose();
                viewMatrix.Transpose();
                projectionMatrix.Transpose();

                DataStream mappedResource;
                deviceContext.MapSubresource(ConstantMatrixBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);
                DMatrixBuffer matrixBuffer = new DMatrixBuffer()
                {
                    world      = worldMatrix,
                    view       = viewMatrix,
                    projection = projectionMatrix
                };
                mappedResource.Write(matrixBuffer);
                deviceContext.UnmapSubresource(ConstantMatrixBuffer, 0);
                int bufferSlotNuber = 0;
                deviceContext.VertexShader.SetConstantBuffer(bufferSlotNuber, ConstantMatrixBuffer);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
        public bool SetShaderParameters(DeviceContext deviceContext, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, Vector4 ambientColour, Vector4 diffuseColour, Vector3 lightDirection)
        {
            try
            {
                // Transpose the matrices to prepare them for shader.
                worldMatrix.Transpose();
                viewMatrix.Transpose();
                projectionMatrix.Transpose();

                // Lock the matrix constant buffer so it can be written to.
                DataStream mappedResource;
                deviceContext.MapSubresource(ConstantMatrixBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);

                // Copy the matrices into the constant buffer.
                DMatrixBuffer matrixBuffer = new DMatrixBuffer()
                {
                    world      = worldMatrix,
                    view       = viewMatrix,
                    projection = projectionMatrix
                };
                mappedResource.Write(matrixBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantMatrixBuffer, 0);

                // Set the position of the constant buffer in the vertex shader.
                int bufferPositionNumber = 0;

                // Finally set the constant buffer in the vertex shader with the updated values.
                deviceContext.VertexShader.SetConstantBuffer(bufferPositionNumber, ConstantMatrixBuffer);

                // Lock the light constant buffer so it can be written to.
                deviceContext.MapSubresource(ConstantLightBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);

                // Copy the lighting variables into the constant buffer.
                DLightBuffer lightBuffer = new DLightBuffer()
                {
                    ambientColor   = ambientColour,
                    diffuseColor   = diffuseColour,
                    lightDirection = lightDirection,
                    padding        = 0.0f
                };
                mappedResource.Write(lightBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantLightBuffer, 0);

                // Set the position of the light constant buffer in the pixel shader.
                bufferPositionNumber = 0;

                // Finally set the light constant buffer in the pixel shader with the updated values.
                deviceContext.PixelShader.SetConstantBuffer(bufferPositionNumber, ConstantLightBuffer);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
示例#3
0
        private bool SetShaderParameters(DeviceContext deviceContext, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, ShaderResourceView colorTexture, ShaderResourceView glowTexture, float glowStrength)
        {
            try
            {
                // Transpose the matrices to prepare them for shader.
                worldMatrix.Transpose();
                viewMatrix.Transpose();
                projectionMatrix.Transpose();

                // Lock the constant buffer so it can be written to.
                DataStream mappedResource;
                deviceContext.MapSubresource(ConstantMatrixBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);

                // Copy the passed in matrices into the constant buffer.
                DMatrixBuffer matrixBuffer = new DMatrixBuffer()
                {
                    world      = worldMatrix,
                    view       = viewMatrix,
                    projection = projectionMatrix
                };
                mappedResource.Write(matrixBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantMatrixBuffer, 0);

                // Set the position of the constant buffer in the vertex shader.
                int bufferPositionNumber = 0;

                // Finally set the constant buffer in the vertex shader with the updated values.
                deviceContext.VertexShader.SetConstantBuffer(bufferPositionNumber, ConstantMatrixBuffer);

                // Lock the constant buffer so it can be written to.
                deviceContext.MapSubresource(ConstantGlowBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);

                // Copy the data into the constant buffer.
                DGlowBufferType glowBuffer = new DGlowBufferType()
                {
                    glowStrength = glowStrength,
                    padding      = Vector3.Zero
                };
                mappedResource.Write(glowBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantGlowBuffer, 0);

                // Set the position of the Glow constant buffer in the pixel shader.
                bufferPositionNumber = 0;
                deviceContext.PixelShader.SetConstantBuffer(bufferPositionNumber, ConstantGlowBuffer);

                // Set shader resource in the pixel shader.
                deviceContext.PixelShader.SetShaderResources(0, colorTexture, glowTexture);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
        private bool SetShaderParameters(DeviceContext deviceContext, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, float tessellationAmount)
        {
            try
            {
                // Transpose the matrices to prepare them for shader.
                worldMatrix.Transpose();
                viewMatrix.Transpose();
                projectionMatrix.Transpose();

                // Lock the constant buffer so it can be written to.
                DataStream mappedResource;
                deviceContext.MapSubresource(ConstantMatrixBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);

                // Copy the matrices into the constant buffer.
                DMatrixBuffer matrixBuffer = new DMatrixBuffer()
                {
                    world      = worldMatrix,
                    view       = viewMatrix,
                    projection = projectionMatrix
                };
                mappedResource.Write(matrixBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantMatrixBuffer, 0);

                // Set the position of the matrix constant buffer in the domain shader.
                int bufferSlotNuber = 0;

                // Finally set the constant buffer in the vertex shader with the updated values.
                deviceContext.DomainShader.SetConstantBuffer(bufferSlotNuber, ConstantMatrixBuffer);

                // Lock the tessellation constant buffer so it can be written to.
                deviceContext.MapSubresource(ConstantTessellationBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);

                // Copy the tessellation data into the constant buffer.
                DTessellationBufferType tessellationBuffer = new DTessellationBufferType()
                {
                    tessellationAmount = tessellationAmount,
                    padding            = new Vector3()
                };
                mappedResource.Write(tessellationBuffer);

                // Unlock the tessellation constant buffer.
                deviceContext.UnmapSubresource(ConstantTessellationBuffer, 0);

                // Set the position of the tessellation constant buffer in the hull shader.
                bufferSlotNuber = 0;

                // Now set the tessellation constant buffer in the hull shader with the updated values.
                deviceContext.HullShader.SetConstantBuffer(bufferSlotNuber, ConstantTessellationBuffer);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
示例#5
0
        private bool SetShaderParameters(DeviceContext deviceContext, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, Vector4 apexColour, Vector4 centerColor)
        {
            // Transpose the matrices to prepare them for the shader.
            // Transpose the matrices to prepare them for shader.
            worldMatrix.Transpose();
            viewMatrix.Transpose();
            projectionMatrix.Transpose();

            // Lock the constant buffer so it can be written to.
            DataStream mappedResource;

            deviceContext.MapSubresource(ConstantMatrixBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);

            // Copy the matrices into the constant buffer.
            DMatrixBuffer matrixBuffer = new DMatrixBuffer()
            {
                world      = worldMatrix,
                view       = viewMatrix,
                projection = projectionMatrix
            };

            mappedResource.Write(matrixBuffer);

            // Unlock the constant buffer.
            deviceContext.UnmapSubresource(ConstantMatrixBuffer, 0);

            // Set the position of the constant buffer in the vertex shader.
            int bufferNumber = 0;

            // Finally set the constant buffer in the vertex shader with the updated values.
            deviceContext.VertexShader.SetConstantBuffer(bufferNumber, ConstantMatrixBuffer);

            // Lock the gradient constant buffer so it can be written to.
            deviceContext.MapSubresource(ConstantGradientBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);

            // Copy the gradient color variables into the constant buffer.
            DGradientBuffer gradientBuffer = new DGradientBuffer()
            {
                apexColor   = apexColour,
                centerColor = centerColor
            };

            mappedResource.Write(gradientBuffer);

            // Unlock the constant buffer.
            deviceContext.UnmapSubresource(ConstantGradientBuffer, 0);

            // Set the position of the gradient constant buffer in the pixel shader.
            bufferNumber = 0;

            // Finally set the gradient constant buffer in the pixel shader with the updated values.
            deviceContext.PixelShader.SetConstantBuffer(bufferNumber, ConstantGradientBuffer);

            return(true);
        }
        private bool SetShaderParameters(DeviceContext deviceContext, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, ShaderResourceView[] textures)
        {
            try
            {
                DataStream mappedResource;

                #region Constant Matrix Buffer
                // Transpose the matrices to prepare them for shader.
                worldMatrix.Transpose();
                viewMatrix.Transpose();
                projectionMatrix.Transpose();

                // Lock the constant buffer so it can be written to.
                deviceContext.MapSubresource(ConstantMatrixBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);

                //// Copy the passed in matrices into the constant buffer.
                DMatrixBuffer matrixBuffer = new DMatrixBuffer()
                {
                    world      = worldMatrix,
                    view       = viewMatrix,
                    projection = projectionMatrix
                };
                mappedResource.Write(matrixBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantMatrixBuffer, 0);

                // Set the position of the constant buffer in the vertex shader.
                int bufferPositionNumber = 0;

                // Finally set the constant buffer in the vertex shader with the updated values.
                deviceContext.VertexShader.SetConstantBuffer(bufferPositionNumber, ConstantMatrixBuffer);

                // Set shader resource in the pixel shader.
                deviceContext.PixelShader.SetShaderResources(0, 2, textures);
                #endregion

                return(true);
            }
            catch
            {
                return(false);
            }
        }
        private bool SetShaderParameters(DeviceContext deviceContext, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, Matrix reflectionMatrix, ShaderResourceView reflectionTexture, ShaderResourceView refractionTexture, ShaderResourceView normalTexture, float waterTranslation, float reflectRefractScale)
        {
            try
            {
                #region Set Matrix Shader Resources
                // Transpose the matrices to prepare them for shader.
                worldMatrix.Transpose();
                viewMatrix.Transpose();
                projectionMatrix.Transpose();

                // Lock the constant buffer so it can be written to.
                DataStream mappedResource;
                deviceContext.MapSubresource(ConstantMatrixBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);

                // Copy the passed in matrices into the constant buffer.
                DMatrixBuffer matrixBuffer = new DMatrixBuffer()
                {
                    world      = worldMatrix,
                    view       = viewMatrix,
                    projection = projectionMatrix
                };
                mappedResource.Write(matrixBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantMatrixBuffer, 0);

                // Set the position of the constant buffer in the vertex shader.
                int bufferPositionNumber = 0;

                // Finally set the constant buffer in the vertex shader with the updated values.
                deviceContext.VertexShader.SetConstantBuffer(bufferPositionNumber, ConstantMatrixBuffer);
                #endregion

                #region Set Reflection Vertex Shader
                // Transpose the reflection matrix to prepare it for the shader.
                reflectionMatrix.Transpose();

                // Lock the constant buffer so it can be written to.
                deviceContext.MapSubresource(ConstantReflectionBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);

                // Copy the matrices into the constant buffer.
                DReflectionBuffer reflectionBuffer = new DReflectionBuffer()
                {
                    reflection = reflectionMatrix
                };
                mappedResource.Write(reflectionBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantReflectionBuffer, 0);

                // Set the position of the constant buffer in the vertex shader.
                bufferPositionNumber = 1;

                // Finally set the constant buffer in the vertex shader with the updated values.
                deviceContext.VertexShader.SetConstantBuffer(bufferPositionNumber, ConstantReflectionBuffer);
                #endregion

                #region Set Water Pixel Shader
                // Lock the water constant buffer so it can be written to.
                deviceContext.MapSubresource(ConstantWaterBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);

                // Copy the matrices into the constant buffer.
                DWaterBuffer waterBuffer = new DWaterBuffer()
                {
                    waterTranslation    = waterTranslation,
                    reflectRefractScale = reflectRefractScale,
                    padding             = Vector2.Zero
                };
                mappedResource.Write(waterBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantWaterBuffer, 0);

                // Set the position of the constant buffer in the vertex shader.
                bufferPositionNumber = 0;

                // Finally set the constant buffer in the vertex shader with the updated values.
                deviceContext.PixelShader.SetConstantBuffer(bufferPositionNumber, ConstantWaterBuffer);
                #endregion

                #region Set Pixel Shader Resources
                // Set the reflection texture resource in the pixel shader.
                deviceContext.PixelShader.SetShaderResources(0, reflectionTexture);

                // Set the refraction texture resource in the pixel shader.
                deviceContext.PixelShader.SetShaderResources(1, refractionTexture);

                // Set the normal map texture resource in the pixel shader.
                deviceContext.PixelShader.SetShaderResources(2, normalTexture);
                #endregion

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        private bool SetShaderParameters(DeviceContext deviceContext, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, ShaderResourceView[] textures, Vector3 lightDirection, Vector4 diffuseColor, Vector3 cameraPosition, Vector4 specularColor, float specularPower)
        {
            try
            {
                #region Constant Matrix Buffer
                // Transpose the matrices to prepare them for shader.
                worldMatrix.Transpose();
                viewMatrix.Transpose();
                projectionMatrix.Transpose();

                // Lock the constant buffer so it can be written to.
                DataStream mappedResource;
                deviceContext.MapSubresource(ConstantMatrixBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);

                // Copy the passed in matrices into the constant buffer.
                DMatrixBuffer matrixBuffer = new DMatrixBuffer()
                {
                    world      = worldMatrix,
                    view       = viewMatrix,
                    projection = projectionMatrix
                };
                mappedResource.Write(matrixBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantMatrixBuffer, 0);

                // Set the position of the constant buffer in the vertex shader.
                int bufferPositionNumber = 0;

                // Finally set the constant buffer in the vertex shader with the updated values.
                deviceContext.VertexShader.SetConstantBuffer(bufferPositionNumber, ConstantMatrixBuffer);

                // Set shader resource in the pixel shader.
                deviceContext.PixelShader.SetShaderResources(0, textures);
                #endregion

                #region Constant Light Buffer
                // Lock the light constant buffer so it can be written to.
                deviceContext.MapSubresource(ConstantLightBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);

                // Copy the lighting variables into the constant buffer.
                DLightBuffer lightBuffer = new DLightBuffer()
                {
                    diffuseColor   = diffuseColor,
                    lightDirection = lightDirection,
                    specularColor  = specularColor,
                    specularPower  = specularPower,
                };
                mappedResource.Write(lightBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantLightBuffer, 0);

                // Set the position of the light constant buffer in the pixel shader.
                bufferPositionNumber = 0;

                // Finally set the light constant buffer in the pixel shader with the updated values.
                deviceContext.PixelShader.SetConstantBuffer(bufferPositionNumber, ConstantLightBuffer);
                #endregion

                #region Constant Camera Buffer
                // Lock the camera constant buffer so it can be written to.
                deviceContext.MapSubresource(ConstantCameraBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);

                // Copy the lighting variables into the constant buffer.
                var cameraBuffer = new DCameraBuffer()
                {
                    cameraPosition = cameraPosition,
                    padding        = 0.0f
                };
                mappedResource.Write(cameraBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantCameraBuffer, 0);

                // Set the position of the light constant buffer in the pixel shader.
                bufferPositionNumber = 1;

                // Now set the camera constant buffer in the vertex shader with the updated values.
                deviceContext.VertexShader.SetConstantBuffer(bufferPositionNumber, ConstantCameraBuffer);
                #endregion

                return(true);
            }
            catch
            {
                return(false);
            }
        }
示例#9
0
        private bool SetShaderParameters(DeviceContext deviceContext, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, ShaderResourceView texture, float screenHeight)
        {
            try
            {
                #region Set Matrix Shader Resources
                // Transpose the matrices to prepare them for shader.
                worldMatrix.Transpose();
                viewMatrix.Transpose();
                projectionMatrix.Transpose();

                // Lock the constant buffer so it can be written to.
                DataStream mappedResource;
                deviceContext.MapSubresource(ConstantMatrixBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);

                // Copy the passed in matrices into the constant buffer.
                DMatrixBuffer matrixBuffer = new DMatrixBuffer()
                {
                    world      = worldMatrix,
                    view       = viewMatrix,
                    projection = projectionMatrix
                };
                mappedResource.Write(matrixBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantMatrixBuffer, 0);

                // Set the position of the constant buffer in the vertex shader.
                int bufferPositionNumber = 0;

                // Finally set the constant buffer in the vertex shader with the updated values.
                deviceContext.VertexShader.SetConstantBuffer(bufferPositionNumber, ConstantMatrixBuffer);

                // Set shader resource in the pixel shader.
                deviceContext.PixelShader.SetShaderResources(0, texture);
                #endregion

                #region Set Screen Size Shader Resources
                // Lock the screen size constant buffer so it can be written to.
                deviceContext.MapSubresource(ConstantScreenSizeBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);

                // Copy the passed in matrices into the constant buffer.
                DScreenSizeBuffer screenSizeBuffer = new DScreenSizeBuffer()
                {
                    screeHeight = screenHeight,
                    padding     = new Vector3()
                };
                mappedResource.Write(screenSizeBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantScreenSizeBuffer, 0);

                // Set the position of the constant buffer in the vertex shader.
                bufferPositionNumber = 1;

                // Now set the constant buffer in the vertex shader with the updated values.
                deviceContext.VertexShader.SetConstantBuffer(bufferPositionNumber, ConstantScreenSizeBuffer);
                #endregion

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
示例#10
0
        private bool SetShaderParameters(DeviceContext deviceContext, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, ShaderResourceView texture, ShaderResourceView normal, Vector3 lightDirection, Vector4 diffuse)
        {
            try
            {
                DataStream mappedResource;
                int        bufferPositionNumber;

                #region Constant Matrix Buffer
                // Transpose the matrices to prepare them for shader.
                worldMatrix.Transpose();
                viewMatrix.Transpose();
                projectionMatrix.Transpose();

                // Lock the constant buffer so it can be written to.
                deviceContext.MapSubresource(ConstantMatrixBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);

                //// Copy the passed in matrices into the constant buffer.
                DMatrixBuffer matrixBuffer = new DMatrixBuffer()
                {
                    world      = worldMatrix,
                    view       = viewMatrix,
                    projection = projectionMatrix
                };
                mappedResource.Write(matrixBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantMatrixBuffer, 0);

                // Set the position of the constant buffer in the vertex shader.
                bufferPositionNumber = 0;

                // Finally set the constant buffer in the vertex shader with the updated values.
                deviceContext.VertexShader.SetConstantBuffer(bufferPositionNumber, ConstantMatrixBuffer);

                // Set shader resource in the pixel shader.
                deviceContext.PixelShader.SetShaderResources(0, texture);
                deviceContext.PixelShader.SetShaderResources(1, normal);
                #endregion

                #region Constant Light Buffer
                // Now for the Lighting Shader.
                // Lock the light constant buffer so it can be written to.
                deviceContext.MapSubresource(ConstantLightBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);

                // Copy the lighting variables into the constant buffer.
                DLightBuffer lightBuffer = new DLightBuffer()
                {
                    // ambientColor = ambiant,
                    diffuseColor   = diffuse,
                    lightDirection = lightDirection,
                    padding        = 0.0f
                                     // specularColor = specularColor,
                                     // specularPower = specularPower
                };
                mappedResource.Write(lightBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantLightBuffer, 0);

                // Set the position of the light constant buffer in the pixel shader.
                bufferPositionNumber = 0;

                // Finally set the light constant buffer in the pixel shader with the updated values.
                deviceContext.PixelShader.SetConstantBuffer(bufferPositionNumber, ConstantLightBuffer);
                #endregion

                return(true);
            }
            catch
            {
                return(false);
            }
        }
        private bool SetShaderParameters(DeviceContext deviceContext, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix)
        {
            try
            {
                Matrix wvp = worldMatrix * viewMatrix * projectionMatrix;
                wvp.Transpose();

                DataStream streamer;
                deviceContext.MapSubresource(ConstantMatrixBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out streamer);
                //streamer.WriteRange(_worldMatrix);
                DMatrixBuffer matrixBuffer = new DMatrixBuffer()
                {
                    worldViewProjection = wvp
                };
                streamer.Write(matrixBuffer);
                //streamer.Write(_worldMatrix);
                deviceContext.UnmapSubresource(ConstantMatrixBuffer, 0); //to update the data on GPU
                int bufferSlotNumberer = 0;
                deviceContext.VertexShader.SetConstantBuffer(bufferSlotNumberer, ConstantMatrixBuffer);
                streamer.Dispose();



                /*Vector3[] total = new Vector3[_worldMatrix.Length];
                 * for (int i = 0; i < _worldMatrix.Length; i++)
                 * {
                 *  total[i].X = _worldMatrix[i].M41;
                 *  total[i].Y = _worldMatrix[i].M42;
                 *  total[i].Z = _worldMatrix[i].M43;
                 *
                 *  // _worldMatrix[i].M41 += instances[i].position.X;
                 *  //_worldMatrix[i].M42 += instances[i].position.Y;
                 *  //_worldMatrix[i].M43 += instances[i].position.Z;
                 *
                 *  //total[i] = _worldMatrix[i] * viewMatrix * projectionMatrix;
                 *  //total[i].Transpose();
                 * }
                 *
                 *
                 * /*DataStream streamer;
                 * deviceContext.MapSubresource(ConstantMatrixBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out streamer);
                 * streamer.WriteRange(total);
                 *
                 * deviceContext.UnmapSubresource(ConstantMatrixBuffer, 0); //to update the data on GPU
                 * int bufferSlotNumber = 0;
                 * deviceContext.VertexShader.SetConstantBuffer(bufferSlotNumber, ConstantMatrixBuffer);
                 * streamer.Dispose();
                 */



                /*//inData MatrixBuffer = new inData();
                 * //MatrixBuffer.instancePosition = new Vector3(-5, 5, -5);
                 * DataStream stream;
                 * deviceContext.MapSubresource(InstanceBuffer, MapMode.WriteNoOverwrite, SharpDX.Direct3D11.MapFlags.None, out stream);
                 * stream.WriteRange(total);
                 * //stream.Write(MatrixBuffer);
                 *
                 * deviceContext.UnmapSubresource(InstanceBuffer, 0); //to update the data on GPU
                 * bufferSlotNumber = 1;
                 * deviceContext.VertexShader.SetConstantBuffer(bufferSlotNumber, InstanceBuffer);
                 * stream.Dispose();*/


                //inData MatrixBuffer = new inData();
                // MatrixBuffer.instancePosition = new Vector3(-5, 5, -5);
                //deviceContext.UpdateSubresource(ref MatrixBuffer, InstanceBuffer);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
        private bool SetShaderParameters(DeviceContext deviceContext, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, ShaderResourceView colorTexture, ShaderResourceView normalTexture, ShaderResourceView refractionTexture, float refractionScale)
        {
            try
            {
                #region Set Matrix Shader Resources
                // Transpose the matrices to prepare them for shader.
                worldMatrix.Transpose();
                viewMatrix.Transpose();
                projectionMatrix.Transpose();

                // Lock the constant buffer so it can be written to.
                DataStream mappedResource;
                deviceContext.MapSubresource(ConstantMatrixBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);

                // Copy the passed in matrices into the constant buffer.
                DMatrixBuffer matrixBuffer = new DMatrixBuffer()
                {
                    world      = worldMatrix,
                    view       = viewMatrix,
                    projection = projectionMatrix
                };
                mappedResource.Write(matrixBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantMatrixBuffer, 0);

                // Set the position of the constant buffer in the vertex shader.
                int bufferPositionNumber = 0;

                // Finally set the constant buffer in the vertex shader with the updated values.
                deviceContext.VertexShader.SetConstantBuffer(bufferPositionNumber, ConstantMatrixBuffer);

                // Set the three shader texture resources in the pixel shader.
                deviceContext.PixelShader.SetShaderResources(0, colorTexture, normalTexture, refractionTexture);
                #endregion

                #region Set Glass Buffer Shader Resources
                // Lock the constant buffer so it can be written to.
                deviceContext.MapSubresource(ConstantGlassBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);

                // Copy the passed in matrices into the constant buffer.
                DGlassBuffer glassBuffer = new DGlassBuffer()
                {
                    refractionScale = refractionScale,
                    padding         = new Vector3()
                };
                mappedResource.Write(glassBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantGlassBuffer, 0);

                // Set the position of the glass constant buffer in the pixel shader.
                bufferPositionNumber = 0;

                // Finally set the constant buffer in the vertex shader with the updated values.
                deviceContext.PixelShader.SetConstantBuffer(bufferPositionNumber, ConstantGlassBuffer);
                #endregion

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        private bool SetShaderParameters(DeviceContext deviceContext, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, ShaderResourceView texture, Vector3 lightDirection, Vector4 ambientColor, Vector4 diffuseColor, Vector4 clipPlane)
        {
            try
            {
                DataStream mappedResource;

                #region Pixel Shader Resources
                // Set shader resource in the pixel shader.
                deviceContext.PixelShader.SetShaderResource(0, texture);
                #endregion

                #region Constant Matrix Buffer
                // Transpose the matrices to prepare them for shader.
                worldMatrix.Transpose();
                viewMatrix.Transpose();
                projectionMatrix.Transpose();

                // Lock the constant buffer so it can be written to.
                deviceContext.MapSubresource(ConstantMatrixBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);

                //// Copy the passed in matrices into the constant buffer.
                DMatrixBuffer matrixBuffer = new DMatrixBuffer()
                {
                    world      = worldMatrix,
                    view       = viewMatrix,
                    projection = projectionMatrix
                };
                mappedResource.Write(matrixBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantMatrixBuffer, 0);

                // Set the position of the constant buffer in the vertex shader.
                int bufferPositionNumber = 0;

                // Finally set the constant buffer in the vertex shader with the updated values.
                deviceContext.VertexShader.SetConstantBuffer(bufferPositionNumber, ConstantMatrixBuffer);
                #endregion

                #region Constant Light Buffer
                // Now for the Lighting Shader.
                // Lock the light constant buffer so it can be written to.
                deviceContext.MapSubresource(ConstantLightBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);

                // Copy the lighting variables into the constant buffer.
                DLightBuffer lightBuffer = new DLightBuffer()
                {
                    ambientColor   = ambientColor,
                    diffuseColor   = diffuseColor,
                    lightDirection = lightDirection,
                };
                mappedResource.Write(lightBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantLightBuffer, 0);

                // Set the position of the light constant buffer in the pixel shader.
                bufferPositionNumber = 0;

                // Finally set the light constant buffer in the pixel shader with the updated values.
                deviceContext.PixelShader.SetConstantBuffer(bufferPositionNumber, ConstantLightBuffer);
                #endregion

                #region Constant Clip Plane Vertex Shader
                // Lock the camera constant buffer so it can be written to.
                deviceContext.MapSubresource(ConstantClipPlaneBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);

                // Copy the lighting variables into the constant buffer.
                DClipPlaneBuffer clipPlaneBuffer = new DClipPlaneBuffer()
                {
                    clipPlane = clipPlane
                };

                mappedResource.Write(clipPlaneBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantClipPlaneBuffer, 0);

                // Set the position of the light constant buffer in the pixel shader.
                bufferPositionNumber = 1;

                // Now set the camera constant buffer in the vertex shader with the updated values.
                deviceContext.VertexShader.SetConstantBuffer(bufferPositionNumber, ConstantClipPlaneBuffer);
                #endregion

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
示例#14
0
        private bool SetShaderParameters(DeviceContext deviceContext, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, ShaderResourceView texture, Vector4[] lightColors, Vector4[] lightPositions)
        {
            try
            {
                DataStream mappedResource;
                int        bufferPositionNumber;

                #region Constant Matrix Buffer
                // Transpose the matrices to prepare them for shader.
                worldMatrix.Transpose();
                viewMatrix.Transpose();
                projectionMatrix.Transpose();

                // Lock the constant buffer so it can be written to.
                deviceContext.MapSubresource(ConstantMatrixBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);

                //// Copy the passed in matrices into the constant buffer.
                DMatrixBuffer matrixBuffer = new DMatrixBuffer()
                {
                    world      = worldMatrix,
                    view       = viewMatrix,
                    projection = projectionMatrix
                };
                mappedResource.Write(matrixBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantMatrixBuffer, 0);

                // Set the position of the constant buffer in the vertex shader.
                bufferPositionNumber = 0;

                // Finally set the constant buffer in the vertex shader with the updated values.
                deviceContext.VertexShader.SetConstantBuffer(bufferPositionNumber, ConstantMatrixBuffer);

                // Set shader resource in the pixel shader.
                deviceContext.PixelShader.SetShaderResource(0, texture);
                #endregion

                #region Light Diffuse Colour Buffer
                // Lock the camera constant buffer so it can be written to.
                deviceContext.MapSubresource(ConstantLightDiffuseColorBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);

                lightColorBuffer.diffuseColor1 = lightColors[0];
                lightColorBuffer.diffuseColor2 = lightColors[1];
                lightColorBuffer.diffuseColor3 = lightColors[2];
                lightColorBuffer.diffuseColor4 = lightColors[3];
                mappedResource.Write(lightColorBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantLightDiffuseColorBuffer, 0);

                // Set the position of the Light Diffuse Color constant buffer in the vertex shader.
                bufferPositionNumber = 0;

                // Finally set the light constant buffer in the pixel shader with the updated values.
                deviceContext.PixelShader.SetConstantBuffer(bufferPositionNumber, ConstantLightDiffuseColorBuffer);
                #endregion

                #region Light Position Buffer
                // Now for the Lighting Position Shader.
                // Lock the light constant buffer so it can be written to.
                deviceContext.MapSubresource(ConstantLightPositionBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);

                lightPositionBuffer.lightPosition1 = lightPositions[0];
                lightPositionBuffer.lightPosition2 = lightPositions[1];
                lightPositionBuffer.lightPosition3 = lightPositions[2];
                lightPositionBuffer.lightPosition4 = lightPositions[3];
                mappedResource.Write(lightPositionBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantLightPositionBuffer, 0);

                /// Set the position of the light constant buffer in the pixel shader.
                bufferPositionNumber = 1;

                // Now set the camera constant buffer in the vertex shader with the updated values.
                deviceContext.VertexShader.SetConstantBuffer(bufferPositionNumber, ConstantLightPositionBuffer);
                #endregion

                return(true);
            }
            catch
            {
                return(false);
            }
        }
        private bool SetShaderParameters(DeviceContext deviceContext, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, ShaderResourceView colorTexture, ShaderResourceView normalTexture, Vector4 diffuseColour, Vector3 lightDirection, float colourTextureBrightness, Vector4 clipPlane)
        {
            try
            {
                // Transpose the matrices to prepare them for shader.
                worldMatrix.Transpose();
                viewMatrix.Transpose();
                projectionMatrix.Transpose();

                // Lock the matrix constant buffer so it can be written to.
                DataStream mappedResource;
                deviceContext.MapSubresource(ConstantMatrixBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);

                // Copy the matrices into the constant buffer.
                DMatrixBuffer matrixBuffer = new DMatrixBuffer()
                {
                    world      = worldMatrix,
                    view       = viewMatrix,
                    projection = projectionMatrix
                };
                mappedResource.Write(matrixBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantMatrixBuffer, 0);

                int bufferPositionNumber = 0;

                // Finally set the constant buffer in the vertex shader with the updated values.
                deviceContext.VertexShader.SetConstantBuffer(bufferPositionNumber, ConstantMatrixBuffer);

                // Lock the clip plane constant buffer so it can be written to.
                deviceContext.MapSubresource(ConstantClipPlaneBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);

                // Copy the clip plane into the clip plane constant buffer.
                DClipPlaneBufferType clipPlaneBuffer = new DClipPlaneBufferType()
                {
                    clipPlane = clipPlane
                };
                mappedResource.Write(clipPlaneBuffer);

                // Unlock the buffer.
                deviceContext.UnmapSubresource(ConstantClipPlaneBuffer, 0);

                // Set the position of the clip plane constant buffer in the vertex shader.
                bufferPositionNumber = 1;

                // Now set the clip plane constant buffer in the vertex shader with the updated values.
                deviceContext.VertexShader.SetConstantBuffer(bufferPositionNumber, ConstantClipPlaneBuffer);

                // Lock the light constant buffer so it can be written to.
                deviceContext.MapSubresource(ConstantLightBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);

                // Copy the lighting variables into the constant buffer.
                DLightBuffer lightBuffer = new DLightBuffer()
                {
                    diffuseColor           = diffuseColour,
                    lightDirection         = lightDirection,
                    colorTextureBrightness = colourTextureBrightness
                };
                mappedResource.Write(lightBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantLightBuffer, 0);

                // Set the position of the light constant buffer in the pixel shader.
                bufferPositionNumber = 0;

                // Finally set the light constant buffer in the pixel shader with the updated values.
                deviceContext.PixelShader.SetConstantBuffer(bufferPositionNumber, ConstantLightBuffer);

                // Set shader texture resources in the pixel shader.
                deviceContext.PixelShader.SetShaderResources(0, colorTexture, normalTexture);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
示例#16
0
        private bool SetShaderParameters(DeviceContext deviceContext, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, ShaderResourceView cloudTexture, ShaderResourceView perturbTexturefloat, float translation, float scale, float brightness)
        {
            try
            {
                // Transpose the matrices to prepare them for shader.
                worldMatrix.Transpose();
                viewMatrix.Transpose();
                projectionMatrix.Transpose();

                // Lock the matrix constant buffer so it can be written to.
                DataStream mappedResource;
                deviceContext.MapSubresource(ConstantMatrixBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);

                // Copy the matrices into the constant buffer.
                DMatrixBuffer matrixBuffer = new DMatrixBuffer()
                {
                    world      = worldMatrix,
                    view       = viewMatrix,
                    projection = projectionMatrix
                };
                mappedResource.Write(matrixBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantMatrixBuffer, 0);

                // Set the position of the constant buffer in the vertex shader.
                int bufferPositionNumber = 0;

                // Finally set the constant buffer in the vertex shader with the updated values.
                deviceContext.VertexShader.SetConstantBuffer(bufferPositionNumber, ConstantMatrixBuffer);

                // Lock the light constant buffer so it can be written to.
                deviceContext.MapSubresource(ConstantSkyBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);

                // Copy the lighting variables into the constant buffer.
                DSkyBufferType skyBuffer = new DSkyBufferType()
                {
                    translation = translation,
                    scale       = scale,
                    brightness  = brightness,
                    padding     = 0.0f
                };
                mappedResource.Write(skyBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantSkyBuffer, 0);

                // Set the position of the light constant buffer in the pixel shader.
                bufferPositionNumber = 0;

                // Finally set the light constant buffer in the pixel shader with the updated values.
                deviceContext.PixelShader.SetConstantBuffer(bufferPositionNumber, ConstantSkyBuffer);

                // Set shader resource in the pixel shader.
                deviceContext.PixelShader.SetShaderResources(0, cloudTexture, perturbTexturefloat);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
示例#17
0
        private bool SetShaderParameters(DeviceContext deviceContext, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, ShaderResourceView texture, ShaderResourceView reflectionTexture, Matrix reflectionMatrix)
        {
            try
            {
                #region Set Matrix Shader Resources
                // Transpose the 3 matrixes first as DirectX 11 requires all input matrices to be transposed for memory alignment reasons.
                worldMatrix.Transpose();
                viewMatrix.Transpose();
                projectionMatrix.Transpose();

                // Lock the constant buffer so it can be written to.
                DataStream mappedResource;
                deviceContext.MapSubresource(ConstantMatrixBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);

                // Copy the passed in matrices into the constant buffer.
                DMatrixBuffer matrixBuffer = new DMatrixBuffer()
                {
                    world      = worldMatrix,
                    view       = viewMatrix,
                    projection = projectionMatrix
                };
                mappedResource.Write(matrixBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantMatrixBuffer, 0);

                // Set the position of the constant buffer in the vertex shader.
                int bufferPositionNumber = 0;

                // Finally set the constant buffer in the vertex shader with the updated values.
                deviceContext.VertexShader.SetConstantBuffer(bufferPositionNumber, ConstantMatrixBuffer);

                // Set shader resource in the pixel shader.
                deviceContext.PixelShader.SetShaderResource(0, texture);
                #endregion

                #region Set Reflection Shader Resources
                // Transpose the reflection matrix first as DirectX 11 requires all input matrices to be transposed for memory alignment reasons.
                reflectionMatrix.Transpose();

                // Lock the constant buffer so it can be written to.
                deviceContext.MapSubresource(ConstantReflectionBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);

                // Copy the matrices into the constant buffer.
                DReflectionBuffer reflectionBuffer = new DReflectionBuffer()
                {
                    reflection = reflectionMatrix
                };
                mappedResource.Write(reflectionBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantReflectionBuffer, 0);

                // Set the position of the constant buffer in the vertex shader.
                bufferPositionNumber = 1;

                // Finally set the constant buffer in the vertex shader with the updated values.
                deviceContext.VertexShader.SetConstantBuffer(bufferPositionNumber, ConstantReflectionBuffer);

                // Set shader resources in the pixel shader.
                deviceContext.PixelShader.SetShaderResources(bufferPositionNumber, reflectionTexture);
                #endregion

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        private bool SetShaderParameters(DeviceContext deviceContext, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, ShaderResourceView texture, Vector4 pixelColor)
        {
            try
            {
                DataStream mappedResource;

                #region Matrix Constant Buffer
                // Transpose the matrices to prepare them for shader.
                worldMatrix.Transpose();
                viewMatrix.Transpose();
                projectionMatrix.Transpose();

                // Lock the constant buffer so it can be written to.
                deviceContext.MapSubresource(ConstantMatrixBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);

                // Copy the matrices into the constant buffer.
                var matrixBuffer = new DMatrixBuffer()
                {
                    world      = worldMatrix,
                    view       = viewMatrix,
                    projection = projectionMatrix
                };
                mappedResource.Write(matrixBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantMatrixBuffer, 0);

                // Set the position of the constant buffer in the vertex shader.
                var bufferNumber = 0;

                //  Now set the constant buffer in the vertex shader with the updated values.
                deviceContext.VertexShader.SetConstantBuffer(bufferNumber, ConstantMatrixBuffer);

                // Set shader resource in the pixel shader.
                deviceContext.PixelShader.SetShaderResource(0, texture);
                #endregion

                #region Pixel Constant Shader
                // Lock the pixel constant buffer so it can be written to.
                deviceContext.MapSubresource(ConstantPixelBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);

                // Copy the matrices into the constant buffer.
                var pixelBuffer = new DPixelBuffer()
                {
                    pixelColor = pixelColor
                };
                mappedResource.Write(pixelBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantPixelBuffer, 0);

                // Set the position of the constant buffer in the vertex shader.
                bufferNumber = 0;

                // Finally set the constant buffer in the vertex shader with the updated values.
                deviceContext.PixelShader.SetConstantBuffer(bufferNumber, ConstantPixelBuffer);
                #endregion

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        private bool SetShaderParameters(DeviceContext deviceContext, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, ShaderResourceView fireTexture, ShaderResourceView noiseTexture, ShaderResourceView alphaTexture, float frameTime, Vector3 scrollSpeeds, Vector3 scales, Vector2 distortion1, Vector2 distortion2, Vector2 distortion3, float distortionScale, float distortionBias)
        {
            try
            {
                #region Set Matrix Shader Resources
                // Transpose the matrices to prepare them for shader.
                worldMatrix.Transpose();
                viewMatrix.Transpose();
                projectionMatrix.Transpose();

                // Lock the constant buffer so it can be written to.
                DataStream mappedResource;
                deviceContext.MapSubresource(ConstantMatrixBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);

                // Copy the passed in matrices into the constant buffer.
                DMatrixBuffer matrixBuffer = new DMatrixBuffer()
                {
                    world      = worldMatrix,
                    view       = viewMatrix,
                    projection = projectionMatrix
                };
                mappedResource.Write(matrixBuffer);

                // Unlock the constant buffer.
                deviceContext.UnmapSubresource(ConstantMatrixBuffer, 0);

                // Set the position of the constant buffer in the vertex shader.
                int bufferPositionNumber = 0;

                // Finally set the constant buffer in the vertex shader with the updated values.
                deviceContext.VertexShader.SetConstantBuffer(bufferPositionNumber, ConstantMatrixBuffer);
                #endregion

                #region Set Noise Constant Buffer Shader Resources
                // Lock the constant buffer so it can be written to.
                deviceContext.MapSubresource(ConstantNoiseBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);

                // Copy the passed in data, frame time, speeds, and scaes into the Noise constant buffer.
                DNoiseBuffer noiseBuffer = new DNoiseBuffer()
                {
                    frameTime    = frameTime,
                    scrollSpeeds = scrollSpeeds,
                    scales       = scales,
                    padding      = 0.0f
                };
                mappedResource.Write(noiseBuffer);

                // Unlock the noise constant buffer.
                deviceContext.UnmapSubresource(ConstantNoiseBuffer, 0);

                // Set the position of the noise constant buffer in the vertex shader.
                bufferPositionNumber = 1;

                // Now set the noise constant buffer in the vertex shader with the updated values.
                deviceContext.VertexShader.SetConstantBuffer(bufferPositionNumber, ConstantNoiseBuffer);
                #endregion

                #region Set the 3 shader texture resources in the pixel shader.
                // Set the three shader texture resources in the pixel shader.
                deviceContext.PixelShader.SetShaderResources(0, fireTexture, noiseTexture, alphaTexture);
                #endregion

                #region Set Distortion Constant Buffer Shader Resources
                // Lock the distortion constant buffer so it can be written to.
                deviceContext.MapSubresource(ConstantDistortionBuffer, MapMode.WriteDiscard, MapFlags.None, out mappedResource);

                // Copy the passed in data, distortion 1 2 & 3 distortionScale & distortionBias into the Noise constant buffer.
                DDistortionBuffer distortionBuffer = new DDistortionBuffer()
                {
                    distprtion1     = distortion1,
                    distprtion2     = distortion2,
                    distprtion3     = distortion3,
                    distortionScale = distortionScale,
                    distortionBias  = distortionBias
                };
                mappedResource.Write(distortionBuffer);

                // Unlock the distortion constant buffer.
                deviceContext.UnmapSubresource(ConstantDistortionBuffer, 0);

                // Set the position of the distortion constant buffer in the pixel shader.
                bufferPositionNumber = 0;

                // Now set the distortion constant buffer in the pixel shader with the updated values.
                deviceContext.PixelShader.SetConstantBuffer(bufferPositionNumber, ConstantDistortionBuffer);
                #endregion

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }