Main Page | Class List | File List | Class Members | File Members

EnvMap.fx File Reference


Defines

#define CUBEMAP_SIZE   128
 size of the cube map taken from the reference point of the object
#define PI   3.14159f
#define _ReduceTexturePS(M)
 Downsamples a cube map face.
#define _ConvolutionPS(M)
 Convolves the values of a cube map of resoultion MxM.
#define _EnvMapDiffuseLocalizedPS(M)
 Calculates diffuse or specular contributions of all texels in SmallEnvironmentMap to the current point. For each texel of SmallEnvironmentMap, function GetContr(int,float3,float3,float3,float3) is called.
#define TechniqueUsingCommonVS(name)
 a helpful macro to define techniques with a common vertex program
#define ReduceTextureTechnique(M)
#define ConvolutionTechnique(M)
#define Technique(name)

Functions

void ReduceTextureVS (float4 position:POSITION, float4 color0:COLOR0, float3 Normal:NORMAL, float2 Tex:TEXCOORD0, out float4 hposition:POSITION, out float4 color:COLOR0, out float2 oTex:TEXCOORD0, out float4 pos:TEXCOORD1)
 _ReduceTexturePS (2)
 _ReduceTexturePS (4)
 _ReduceTexturePS (8)
 _ReduceTexturePS (16)
float4 GetContr (float3 q, float3 L)
 Returns the precalculated contribution of a texel with regard to the specified query direction.
_ConvolutionVS_output ConvolutionVS (_ConvolutionVS_input IN)
 _ConvolutionPS (2)
 _ConvolutionPS (4)
 _ConvolutionPS (8)
 _ConvolutionPS (16)
_EnvMapVS_output EnvMapVS (_EnvMapVS_input IN)
float4 EnvMapDiffuseClassicPS (_EnvMapVS_output IN)
 Determines diffuse or specular illumination with a single lookup into PreconvolvedEnvironmentMap.
float4 GetContr (int M, float3 L, float3 pos, float3 N, float3 V)
 Calculates the contribution of a single texel of SmallEnvironmentMap to the illumination of the shaded point. To compute reflectivity, precalculated integral values are used.
 _EnvMapDiffuseLocalizedPS (2)
 _EnvMapDiffuseLocalizedPS (4)
 _EnvMapDiffuseLocalizedPS (8)
 _EnvMapDiffuseLocalizedPS (16)
float4 EnvMapDiffuseLocalized5TexPS (_EnvMapVS_output IN)
 Calculates diffuse or specular contributions of the 5 "most important" texels of SmallEnvironmentMap to the current point. For these texels, function GetContr(int,float3,float3,float3,float3) is called.
_IlluminatedSceneVS_output IlluminatedSceneVS (_IlluminatedSceneVS_input IN)
float4 IlluminatedScenePS (_IlluminatedSceneVS_output IN)
 Displays the environment with a simple shading.
 TechniqueUsingCommonVS (EnvMapDiffuseClassic)
 TechniqueUsingCommonVS (EnvMapDiffuseLocalized5Tex)
 TechniqueUsingCommonVS (EnvMapDiffuseLocalized2)
 TechniqueUsingCommonVS (EnvMapDiffuseLocalized4)
 TechniqueUsingCommonVS (EnvMapDiffuseLocalized8)
 TechniqueUsingCommonVS (EnvMapDiffuseLocalized16)
 ReduceTextureTechnique (2)
 ReduceTextureTechnique (4)
 ReduceTextureTechnique (8)
 ReduceTextureTechnique (16)
 ConvolutionTechnique (2)
 ConvolutionTechnique (4)
 ConvolutionTechnique (8)
 ConvolutionTechnique (16)
 Technique (IlluminatedScene)

Variables

int LR_CUBEMAP_SIZE
 size of the cube map for diffuse/glossy reflections
float4x4 World
 World matrix for the current object.
float4x4 WorldIT
 World matrix IT (inverse transposed) to transform surface normals of the current object.
float4x4 WorldView
 World * View matrix.
float4x4 WorldViewProjection
 World * View * Projection matrix.
float texel_size
 upload this constant every time the viewport changes
float4 eyePos
 current eye (camera) position
float4 reference_pos
 Reference point for the last cube map generation.
int nFace
int iShowCubeMap
float4 objColor
float intensity
float shininess
float brightness
texture EnvironmentMap
texture SmallEnvironmentMap
texture PreconvolvedEnvironmentMap
texture Decoration
sampler EnvironmentMapSampler
sampler PreconvolvedEnvironmentMapSampler
sampler SmallEnvironmentMapSampler
sampler DecorationSampler

Define Documentation

#define _ConvolutionPS  ) 
 

Convolves the values of a cube map of resoultion MxM.

Calculates the diffuse/specular irradiance map of resolution LR_CUBEMAP_SIZE by summing up the contributions of all cube map texels with regard to the current query direction.

#define _EnvMapDiffuseLocalizedPS  ) 
 

Value:

float4 EnvMapDiffuseLocalized##M##PS( _EnvMapVS_output IN ) : COLOR     \
{                                                                                                                                                                       \
        IN.View = -normalize( IN.View );                                                                                                \
        IN.Normal = normalize( IN.Normal );                                                                                             \
        IN.Position -= reference_pos.xyz;                               /* relative to the ref.point */ \
                                                                                                                                                                        \
        float3 R = -reflect( IN.View, IN.Normal );              /* reflection direction */              \
                                                                                                                                                                        \
    float4 I = 0;                                                                                                                                       \
                                                                                                                                                                        \
        for (int x = 0; x < M; x++)                     /* foreach texel */                                                     \
         for (int y = 0; y < M; y++)                                                                                                    \
         {                                                                                                                                                              \
                /* compute intensity for 6 texels with equal solid angles */                            \
                                                                                                                                                                        \
                float2 tpos = float2( (x+0.5f)/M, (y+0.5f)/M ); /* texture coord (0..1) */      \
                                                                                                                                                                        \
            float2 p = float2(tpos.x, 1-tpos.y);                                                                                \
            p.xy = 2*p.xy - 1;                                                          /* position (-1..1) */          \
                                                                                                                                                                        \
                I += GetContr( M, float3(p.x, p.y,  1), IN.Position, IN.Normal, IN.View );      \
                I += GetContr( M, float3(p.x, p.y, -1), IN.Position, IN.Normal, IN.View );      \
                I += GetContr( M, float3(p.x,  1, p.y), IN.Position, IN.Normal, IN.View );      \
                I += GetContr( M, float3(p.x, -1, p.y), IN.Position, IN.Normal, IN.View );      \
                I += GetContr( M, float3(1,  p.x, p.y), IN.Position, IN.Normal, IN.View );      \
                I += GetContr( M, float3(-1, p.x, p.y), IN.Position, IN.Normal, IN.View );      \
        }                                                                                                                                                               \
                                                                                                                                                                        \
        return intensity * I;                                                                                                                   \
}
Calculates diffuse or specular contributions of all texels in SmallEnvironmentMap to the current point. For each texel of SmallEnvironmentMap, function GetContr(int,float3,float3,float3,float3) is called.

#define _ReduceTexturePS  ) 
 

Value:

float4 ReduceTexture##M##PS( float2 Tex : TEXCOORD0,                                                    \
                                  float4 pos : TEXCOORD1,                                                                                       \
                                  float4 color0 : COLOR0 ) : COLOR0                                                                     \
{                                                                                                                                                                       \
        /* offset to texel center */                                                                                                    \
        pos.xy += float2(1/(float)CUBEMAP_SIZE, -1/(float)CUBEMAP_SIZE);                                \
        /* transform position into texture coord */                                                                             \
    float2 tpos = pos.xy/2+0.5;         /* rescale from -1..1 into range 0..1 */                \
    tpos.y = 1-tpos.y;                                                                                                                          \
                                                                                                                                                                        \
    float2 t;                                                                                                                                           \
    float4 color = 0;                                                                                                                           \
        const int RATE = CUBEMAP_SIZE / M;                                                                                              \
                                                                                                                                                                        \
    for (int i = 0; i < RATE; i++)                                                                                                      \
     for (int j = 0; j < RATE; j++)                                                                                                     \
    {                                                                                                                                                           \
                t.x = tpos.x + i/(float)CUBEMAP_SIZE;                                                                           \
                t.y = tpos.y + j/(float)CUBEMAP_SIZE;                                                                           \
                color += tex2D(DecorationSampler, t) / (RATE * RATE);                                           \
    }                                                                                                                                                           \
        return color;                                                                                                                                   \
}
Downsamples a cube map face.

#define ConvolutionTechnique  ) 
 

Value:

;                                                                       \
        technique Convolution##M                                                                                \
        {                                                                                                                               \
            pass p0                                                                                                             \
            {                                                                                                                   \
                    VertexShader = compile vs_3_0 ConvolutionVS();                      \
                    PixelShader  = compile ps_3_0 Convolution##M##PS();         \
                }                                                                                                                       \
        }

#define CUBEMAP_SIZE   128
 

size of the cube map taken from the reference point of the object

#define PI   3.14159f
 

#define ReduceTextureTechnique  ) 
 

Value:

;                                                                       \
        technique ReduceTexture##M                                                                              \
        {                                                                                                                               \
            pass p0                                                                                                             \
            {                                                                                                                   \
                    VertexShader = compile vs_3_0 ReduceTextureVS();            \
                    PixelShader  = compile ps_3_0 ReduceTexture##M##PS();       \
                }                                                                                                                       \
        }

#define Technique name   ) 
 

Value:

;                                                               \
        technique name                                                                          \
        {                                                                                                       \
            pass p0                                                                                     \
            {                                                                                           \
                    VertexShader = compile vs_3_0 name##VS();   \
                    PixelShader  = compile ps_3_0 name##PS();   \
                }                                                                                               \
        }
a helpful macro to define techniques where the name of EnvMapVS program is <techniquename>VS and the name of PS program is <techniquename>PS

#define TechniqueUsingCommonVS name   ) 
 

Value:

;                                                               \
        technique name                                                                                                  \
        {                                                                                                                               \
            pass p0                                                                                                             \
            {                                                                                                                   \
                    VertexShader = compile vs_3_0 EnvMapVS();                           \
                    PixelShader  = compile ps_3_0 name##PS();                           \
                }                                                                                                                       \
        }
a helpful macro to define techniques with a common vertex program


Function Documentation

_ConvolutionPS 16   ) 
 

_ConvolutionPS  ) 
 

_ConvolutionPS  ) 
 

_ConvolutionPS  ) 
 

_EnvMapDiffuseLocalizedPS 16   ) 
 

_EnvMapDiffuseLocalizedPS  ) 
 

_EnvMapDiffuseLocalizedPS  ) 
 

_EnvMapDiffuseLocalizedPS  ) 
 

_ReduceTexturePS 16   ) 
 

_ReduceTexturePS  ) 
 

_ReduceTexturePS  ) 
 

_ReduceTexturePS  ) 
 

ConvolutionTechnique 16   ) 
 

ConvolutionTechnique  ) 
 

ConvolutionTechnique  ) 
 

ConvolutionTechnique  ) 
 

_ConvolutionVS_output ConvolutionVS _ConvolutionVS_input  IN  ) 
 

float4 EnvMapDiffuseClassicPS _EnvMapVS_output  IN  ) 
 

Determines diffuse or specular illumination with a single lookup into PreconvolvedEnvironmentMap.

Parameters:
PreconvolvedEnvironmentMap is bound to EnvMap::pCubeTexturePreConvolved (cube map of resolution LR_CUBEMAP_SIZE)

float4 EnvMapDiffuseLocalized5TexPS _EnvMapVS_output  IN  ) 
 

Calculates diffuse or specular contributions of the 5 "most important" texels of SmallEnvironmentMap to the current point. For these texels, function GetContr(int,float3,float3,float3,float3) is called.

_EnvMapVS_output EnvMapVS _EnvMapVS_input  IN  ) 
 

float4 GetContr int  M,
float3  L,
float3  pos,
float3  N,
float3  V
 

Calculates the contribution of a single texel of SmallEnvironmentMap to the illumination of the shaded point. To compute reflectivity, precalculated integral values are used.

Parameters:
L vector pointing to the center of the texel under examination. We assume that the largest coordinate component of L is equal to one, i.e. L points to the face of a cube of edge length of 2.
pos is the position of the shaded point
N is the surface normal at the shaded point
V is the viewing direction at the shaded point

float4 GetContr float3  q,
float3  L
 

Returns the precalculated contribution of a texel with regard to the specified query direction.

Parameters:
q query direction (i.e. surface normal in diffuse case, ideal reflection direction in specular case).
L vector pointing to the texel center

float4 IlluminatedScenePS _IlluminatedSceneVS_output  IN  ) 
 

Displays the environment with a simple shading.

_IlluminatedSceneVS_output IlluminatedSceneVS _IlluminatedSceneVS_input  IN  ) 
 

ReduceTextureTechnique 16   ) 
 

ReduceTextureTechnique  ) 
 

ReduceTextureTechnique  ) 
 

ReduceTextureTechnique  ) 
 

void ReduceTextureVS float4 position:POSITION  ,
float4 color0:COLOR0  ,
float3 Normal:NORMAL  ,
float2 Tex:TEXCOORD0  ,
out float4 hposition:POSITION  ,
out float4 color:COLOR0  ,
out float2 oTex:TEXCOORD0  ,
out float4 pos:TEXCOORD1 
 

Technique IlluminatedScene   ) 
 

TechniqueUsingCommonVS EnvMapDiffuseLocalized16   ) 
 

TechniqueUsingCommonVS EnvMapDiffuseLocalized8   ) 
 

TechniqueUsingCommonVS EnvMapDiffuseLocalized4   ) 
 

TechniqueUsingCommonVS EnvMapDiffuseLocalized2   ) 
 

TechniqueUsingCommonVS EnvMapDiffuseLocalized5Tex   ) 
 

TechniqueUsingCommonVS EnvMapDiffuseClassic   ) 
 


Variable Documentation

float brightness
 

texture Decoration
 

sampler DecorationSampler
 

Initial value:

 sampler_state 
{
    Texture   = <Decoration>;
    MinFilter = LINEAR;
    MagFilter = LINEAR;
    
    AddressU  = CLAMP; 
    AddressV  = CLAMP; 
}

texture EnvironmentMap
 

sampler EnvironmentMapSampler
 

Initial value:

 sampler_state 
{
    
    Texture   = <EnvironmentMap>;
    AddressU  = WRAP;
    AddressV  = WRAP;
}

float4 eyePos
 

current eye (camera) position

float intensity
 

int iShowCubeMap
 

int LR_CUBEMAP_SIZE
 

size of the cube map for diffuse/glossy reflections

int nFace
 

float4 objColor
 

texture PreconvolvedEnvironmentMap
 

sampler PreconvolvedEnvironmentMapSampler
 

Initial value:

 sampler_state 
{
    MinFilter = LINEAR;
    MagFilter = LINEAR;
    
    Texture   = <PreconvolvedEnvironmentMap>;
    AddressU  = WRAP;
    AddressV  = WRAP;
}

float4 reference_pos
 

Reference point for the last cube map generation.

float shininess
 

texture SmallEnvironmentMap
 

sampler SmallEnvironmentMapSampler
 

Initial value:

 sampler_state 
{



    MinFilter = LINEAR;
    MagFilter = LINEAR;

    
    Texture   = <SmallEnvironmentMap>;
    AddressU  = WRAP;
    AddressV  = WRAP;
}

float texel_size
 

upload this constant every time the viewport changes

float4x4 World
 

World matrix for the current object.

float4x4 WorldIT
 

World matrix IT (inverse transposed) to transform surface normals of the current object.

float4x4 WorldView
 

World * View matrix.

float4x4 WorldViewProjection
 

World * View * Projection matrix.


Generated on Wed Aug 23 00:00:39 2006 for Indirect Environment Mapping by  doxygen 1.4.2