File: CubeMap.fx

package info (click to toggle)
libwildmagic 5.17%2Bcleaned1-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 90,124 kB
  • sloc: cpp: 215,940; csh: 637; sh: 91; makefile: 40
file content (57 lines) | stat: -rw-r--r-- 1,829 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
49
50
51
52
53
54
55
56
57
samplerCUBE CubeMapSampler = sampler_state
{
   MinFilter = Nearest;
   MagFilter = Linear;
   WrapS     = Clamp;
   WrapT     = Clamp;
};

void v_CubeMap
(
    in float3 modelPosition : POSITION,
    in float3 modelNormal : NORMAL,
    in float3 modelColor : COLOR,
    out float4 clipPosition : POSITION,
    out float4 vertexColor : COLOR,
    out float3 cubeTCoord : TEXCOORD0,
    uniform float4x4 PVWMatrix,
    uniform float4x4 WMatrix,
    uniform float3 CameraWorldPosition
)
{
    // Transform the position from model space to clip space.
    float4 hModelPosition = float4(modelPosition, 1.0f);
    clipPosition = mul(PVWMatrix, hModelPosition);

    // Transform the position from model space to world space.
    float3 worldPosition = mul(WMatrix, hModelPosition).xyz;

    // Transform the normal from model space to world space.
    float4 hModelNormal = float4(modelNormal, 0.0f);
    float3 worldNormal = normalize(mul(WMatrix, hModelNormal)).xyz;

    // Calculate the eye direction.  The direction does not have to be
    // normalized, because the texture coordinates for the cube map are
    // invariant to scaling.  Thus, directions V and s*V for s > 0
    // generate the same texture coordinates.
    float3 eyeDirection = worldPosition - CameraWorldPosition;

    // Calculate the reflected vector.
    cubeTCoord = reflect(eyeDirection, worldNormal);

    // Pass through the model color.
    vertexColor.rgb = modelColor;
    vertexColor.a = 1.0f;
}

void p_CubeMap
(
    in float4 vertexColor : COLOR,
    in float3 cubeTCoord : TEXCOORD0,
    out float4 pixelColor : COLOR,
    uniform float Reflectivity
)
{
    float4 reflectedColor = texCUBE(CubeMapSampler, cubeTCoord);
    pixelColor = lerp(vertexColor, reflectedColor, Reflectivity);
}