public void SetShaderParameters(DeviceContext deviceContext, BufferTypes.WorldViewProj WWPComputed, int indexCount) { throw new NotImplementedException(); }
public void SetShaderParameters(DeviceContext deviceContext, BufferTypes.WorldViewProj WWPComputed, int indexCount) { //no time for refining this, it should be more flexible //like: if usingCamera ==> createCameraBuffer, if usingSpecularLightig.... // i should probably use some behavioral/creatioal pattern // this is probably more about behavior..... this.indexCount = indexCount; this.deviceContext = deviceContext; //WriteToSubresource<WorldViewProjAdvanced>(constantMatrixBuffer, WWPComputed); WriteToSubresource <BufferTypes.WorldViewProj>(constantMatrixBuffer, WWPComputed); int bufferNumber = 0; try { deviceContext.VertexShader.SetConstantBuffer(bufferNumber, constantMatrixBuffer); } catch (Exception ex) { throw new Exception("D3D11 failed to set constant buffer" + ex); } // Set shader resource in the pixel shader. if (shader != ShaderName.Color) { //useTexture deviceContext.PixelShader.SetShaderResources(0, TextureCollection); } Vector4 diffuseColor; Vector3 lightDirection; Vector4 ambientColor; if (shader == ShaderName.ParallaxMapping || shader == ShaderName.Bumpmaping || shader == ShaderName.Specular || shader == ShaderName.DirectionalLightingParallaxMapping) { UseCamera(); } if (shader == ShaderName.DirectionalLightingParallaxMapping) { BufferTypes.Material material = new BufferTypes.Material(); material.ambient = new Vector4(0.3f, 0.3f, 0.3f, 1.0f); material.diffuse = new Vector4(0.7f, 0.7f, 0.7f, 1.0f); material.specular = new Vector4(1.0f, 1.0f, 1.0f, 1.0f); material.shininess = 90.0f; WriteToSubresource <BufferTypes.Material>(constantLightBuffer, material); // Finally set the light constant buffer in the pixel shader with the updated values. deviceContext.PixelShader.SetConstantBuffer(1, constantLightBuffer); //deviceContext.VertexShader.SetConstantBuffer(2, constantLightBuffer); } if (shader == ShaderName.ParallaxMapping || shader == ShaderName.Diffuse || shader == ShaderName.Bumpmaping || shader == ShaderName.LightingEffect) //|| shader == ShaderName.DirectionalLightingParallaxMapping { //another ugly part if (shader == ShaderName.Diffuse) { diffuseColor = new Vector4(1, 0, 1, 1); lightDirection = new Vector3(1, 0, 1); } else { diffuseColor = new Vector4(1, 1, 1, 1f); //Vector4 diffuseColor = new Vector4(1, 0, 1, 1); lightDirection = new Vector3(1.0f, 0.0f, 1.0f); //lightDirection = new Vector3(.4f, 0, 1); } var lightBuffer = new BufferTypes.DiffuseLightBufferType() { diffuseColor = diffuseColor, lightDirection = lightDirection, padding = 0, }; WriteToSubresource <BufferTypes.DiffuseLightBufferType>(constantLightBuffer, lightBuffer); // Finally set the light constant buffer in the pixel shader with the updated values. if (shader == ShaderName.ParallaxMapping) { deviceContext.VertexShader.SetConstantBuffer(2, constantLightBuffer); } else { deviceContext.PixelShader.SetConstantBuffer(0, constantLightBuffer); } } if (shader == ShaderName.Ambient) { diffuseColor = new Vector4(1, 1, 1f, 1f); lightDirection = new Vector3(1, .5f, 0); ambientColor = new Vector4(0.15f, 0.15f, 0.15f, 1.0f); var ambientLightBuffer = new BufferTypes.AmbientLightBufferType() { ambientColor = ambientColor, diffuseColor = diffuseColor, lightDirection = lightDirection, padding = 0, }; WriteToSubresource <BufferTypes.AmbientLightBufferType>(constantLightBuffer, ambientLightBuffer); // Finally set the light constant buffer in the pixel shader with the updated values. deviceContext.PixelShader.SetConstantBuffer(bufferNumber, constantLightBuffer); } if (shader == ShaderName.Specular) { diffuseColor = new Vector4(1, 1, 1f, 1f); lightDirection = new Vector3(1, 1, 1); ambientColor = new Vector4(0.15f, 0.15f, 0.15f, 1.0f); Vector4 specularColor = new Vector4(1, 1, 1, 1); float specularPower = 32; var specularLightBuffer = new BufferTypes.SpecularLightBufferType() { ambientColor = ambientColor, diffuseColor = diffuseColor, lightDirection = lightDirection, specularColor = specularColor, specularPower = specularPower, }; WriteToSubresource <BufferTypes.SpecularLightBufferType>(constantLightBuffer, specularLightBuffer); bufferNumber = 0; // Finally set the light constant buffer in the pixel shader with the updated values. deviceContext.PixelShader.SetConstantBuffer(bufferNumber, constantLightBuffer); } }