Graphics Reference
In-Depth Information
// Calculate reflection (if any)
if (IsReflective) {
float3 reflection = reflect(-toEye, normal);
color = lerp(color, Reflection.Sample(Sampler,
reflection).rgb, ReflectionAmount);
}
// Calculate final alpha value and return
float alpha = pixel.Diffuse.a * sample.a;
return float4(color, alpha);
}
8. Within each of our existing pixel shaders (for example, BlinnPhongPS.hlsl ) that
will implement reflections, add the highlighted changes (as shown in the preceding
code snippet), except for the function signature. This includes the TextureCube
shader resource and blending of the reflection sample.
9. This completes our HLSL source changes. We will now make the corresponding
changes to the C# PerMaterial structure, create our DynamicCubeMap renderer
class, and update our MeshRenderer class to use the cube map for reflections.
10. Within the ConstantBuffers.cs file, add the IsReflective and
ReflectionAmount properties to the PerMaterial structure.
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct PerMaterial {
...
public uint IsReflective; //reflective (0 false, 1 true)
public float ReflectionAmount; // how reflective? 0-1
...
}
11. Create a new renderer class descending from Common.RendererBase called
DynamicCubeMap .
using SharpDX;
using SharpDX.DXGI;
using SharpDX.Direct3D11;
using Common;
using Buffer = SharpDX.Direct3D11.Buffer;
// Represents a dynamic cubic environment map (cube map)
public class DynamicCubeMap: Common.RendererBase
{
...
}
 
Search WWH ::




Custom Search