File: SphereMap.fx

package info (click to toggle)
libwildmagic 5.13-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 89,572 kB
  • ctags: 26,264
  • sloc: cpp: 210,924; csh: 637; sh: 95; makefile: 36
file content (48 lines) | stat: -rw-r--r-- 1,482 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
sampler2D BaseSampler = sampler_state
{
   MinFilter = Nearest;
   MagFilter = Linear;
   WrapS     = Clamp;
   WrapT     = Clamp;
};

void v_SphereMap
(
    in float3 modelPosition : POSITION,
    in float3 modelNormal : TEXCOORD1,
    out float4 clipPosition : POSITION,
    out float2 vertexTCoord : TEXCOORD0,
    uniform float4x4 PVWMatrix,
    uniform float4x4 VWMatrix
)
{
    // Transform the position from model space to clip space.
    float4 hModelPosition = float4(modelPosition, 1.0f);
    clipPosition = mul(PVWMatrix, hModelPosition);

    // Transform the normal from model space to camera space.
    float4 hModelNormal = float4(modelNormal, 0.0f);
    float3 cameraSpaceNormal = normalize(mul(VWMatrix, hModelNormal).xyz);

    // Calculate the eye direction in camera space.
    float4 cameraSpacePosition = mul(VWMatrix, hModelPosition);
    float3 eyeDirection = normalize(cameraSpacePosition.xyz);

    // Calculate the reflection vector.
    float3 reflection = reflect(eyeDirection, cameraSpaceNormal);

    // Calculate the texture coordinates.
    float oneMRZ = 1.0f - reflection.z;
    float invLength = 1.0f/sqrt(reflection.x*reflection.x +
        reflection.y*reflection.y + oneMRZ*oneMRZ);
    vertexTCoord = 0.5f*(reflection.xy*invLength + 1.0f);
}

void p_SphereMap
(
    in float2 vertexTCoord : TEXCOORD0, 
    out float4 pixelColor : COLOR
)
{
    pixelColor = tex2D(BaseSampler, vertexTCoord);
}