Graphics Reference
In-Depth Information
// Textures
Texture2D NormalTexture
: register( t0 );
Texture2D DiffuseAlbedoTexture
: register( t1 );
Texture2D SpecularAlbedoTexture
: register( t2 );
Texture2D PositionTexture
: register( t3 );
// Constants
cbuffen LightParams
{
float3 LightPos;
float3 LightColor;
float3 LightDirection;
float2 SpotlightAngles;
float4 LightRange;
}i
cbuffer CameraParams
{
float3 CameraPos;
};
II Helper function for extracting G-Buffer attributes
void GetGBufferAttributes( in float2 screenPos, out float3 normal,
out float3 position,
out float3 diffuseAlbedo, out float3 specularAlbedo,
out float specularPower )
{
// Determine our indices for sampling the texture based on the current
// screen position
int3 samplelndices = int3( screenPos.xy, 0 );
normal = NormalTexture. Load( sampleIndices ).xyz;
position = PositionTexture. Load( sampleIndices ).xyz;
diffuseAlbedo = DiffuseAlbedoTexture. Load( sampleIndices ).xyz;
float4 spec = SpecularAlbedoTexture. Load( sampleIndices );
specularAlbedo = spec.xyz;
specularPower = spec.w;
}
// Calculates the lighting term for a single G-Buffer texel
float3 Calctighting( in float3 normal,
in float3 position,
in float3 diffuseAlbedo,
in float3 specularAlbedo,
in float specularPower )
{
// Calculate the diffuse term
float3 L = 0;
float attenuation = 1.0f;
#if POINTLIGHT || SPOTLIGHT
// Base the the light vector on the light position
L = LightPos - position;
Search WWH ::




Custom Search