HLSL Development Cookbook

HLSL Development Cookbook

Doron Feinstein

Language: English

Pages: 224

ISBN: 1849694206

Format: PDF / Kindle (mobi) / ePub


Written in an engaging yet practical manner, HLSL Development Cookbook allows you to pick the recipes you need as and when they are required. If you have some basic Direct3D knowledge and want to give your work some additional visual impact by utilizing advanced rendering techniques, then this book is for you. It is also ideal for those seeking to make the transition from DirectX 9 to DirectX 11, and those who want to implement powerful shaders with the High Level Shader Language (HLSL).

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

each light before passing the values to the GPU. All four light ranges are stored in a single four-component constant: float4 LightRange; All four lights' capsule lengths are stored in a single four-component constant. For noncapsule lights just store the respected value to 0: float4 CapsuleLen; Spot light's cosine outer cone angle is again stored in a four-component constant. For nonspot light sources set the respected value to -2: float4 SpotCosOuterCone; Unlike the single spot light, for

the easiest to implement and requires the least math to encode and decode. It supports alpha blending. The unused alpha channel can be used for storing the encoded specular power. Cons: Low quality normals after decoding and a poor use of the 24 bit of memory used by this method. Reducing the normals precision due to storage limitations can lead to what is known as bending, especially when calculating specular lighting. Bending usually shows up as a non-smooth color. This brings us to the two

Reconstruct the world position float3 position = CalcWorldPos(In.cpPos, gbd.LinearDepth); // Calculate the light contribution float4 finalColor; finalColor.xyz = CalcPoint(position, mat); finalColor.w = 1.0; return finalColor; } This function takes the clip space position and texture coordinates as input and outputs the lit pixel value. As you can see, this is almost the exact copy of the directional light, the only thing that changed is the call to the CalcPoint function. The CalcPoint function

pixel's depth value corresponding to the cube-map face this pixel belongs to. For that we will only need two of the projection parameters from the projection matrix we prepared. The updated pixel shader constant buffer is as follows: cbuffer cbPointLightPixel : register( b1 ) { 88 Chapter 3 float3 PointLightPos : packoffset( c0 ); float PointLightRangeRcp : packoffset( c0.w ); float3 PointColor : packoffset( c1 ); float2 LightPerspectiveValues : packoffset( c2 ); } The new constant buffer

UAV as output. We will be using the following compute shader constant buffer for all computations: cbufferDownScaleConstants : register( b0 ) { uint2 Res : packoffset( c0 ); float2 ResRcp : packoffset( c0.z ); float4 ProjParams : packoffset( c1 ); float4x4 ViewMatrix : packoffset( c2 ); float OffsetRadius : packoffset( c6 ); float Radius : packoffset( c6.y ); } Set the following values to the constant buffer: ff Res: This is vertical and horizontal quarter-sized resolution ff ResRcp: This is

Download sample

Download