source: GTP/trunk/App/Demos/Illum/DepthOfField/shaders/BumpMapping.fx @ 765

Revision 765, 3.8 KB checked in by szirmay, 18 years ago (diff)

Added a folder remotely

Line 
1float4x4 WorldViewProj;
2float4x4 WorldView;
3float4x4 WorldViewIT;
4float3 mCameraPos;              // model-space Camera position
5float3 mLightPos;               // model-space Light position
6float  focalDist;
7float  focalRange;
8//------------------------------------------------------------------------------------
9// macro definition for filtered samplers
10//------------------------------------------------------------------------------------
11#define SAMPLER_LINEAR(g_samplerMap, g_txMap);  \
12        sampler2D g_samplerMap = sampler_state {        \
13    Texture = <g_txMap>;                                                \
14    MinFilter = Linear;                                                 \
15    MagFilter = Linear;                                                 \
16    MipFilter = Linear;                                                 \
17    AddressU  = WRAP;                                                   \
18    AddressV  = WRAP;                                                   \
19};
20
21texture ColorMap;
22SAMPLER_LINEAR(ColorMapSampler, ColorMap);
23texture BumpMap;
24SAMPLER_LINEAR(BumpMapSampler,BumpMap);
25
26// Illumination functions
27#include "illum.hlsl"
28
29struct VS_INPUT {
30                float4 Position  : POSITION;
31                float3 Normal    : NORMAL;                                     
32                float3 Binormal  : BINORMAL;
33                float3 Tangent   : TANGENT;
34                float4 TexCoord0 : TEXCOORD0;
35};
36
37struct VS_OUTPUT {
38        float4 hPosition : POSITION;     // point in normalized device space before homogeneous division
39        float2 TexCoord  : TEXCOORD0;    // texture coordinates
40        float3 tView     : TEXCOORD1;    // tangent space view vector
41        float3 tLight    : TEXCOORD2;    // tangent space light vector
42                float  Depth    : TEXCOORD3;
43};
44
45struct PS_OUTPUT {
46                float4 Color : COLOR0;
47                float4 Depth : COLOR1;
48};
49
50//------------------------------------------------------------------------------------
51//
52// Base vertex shader: vertex shader for all methods: calculates tangent-space
53//              tLight, tView, hPosition vectors
54//
55//------------------------------------------------------------------------------------
56VS_OUTPUT BumpVS(VS_INPUT IN)
57{
58        VS_OUTPUT output;
59   
60        // object-space tangent matrix
61                float3x3 Tan = float3x3(normalize(IN.Tangent), normalize(IN.Binormal), IN.Normal);
62        // position in view-space
63        float3 P = mul(IN.Position, WorldView);
64                // model-space view vector       
65                float3 mView = mCameraPos - IN.Position;
66                // model-space light vector
67                float3 mLight = mLightPos - IN.Position;
68                // tangent-space view vector
69                output.tView = mul(Tan, mView);
70                // tangent-space light vector
71                output.tLight =  mul(Tan, mLight);
72        // vertex position before homogenious division
73        output.hPosition = mul(IN.Position, WorldViewProj);
74                // tex coordinates passed to pixel shader
75        output.TexCoord = IN.TexCoord0;
76                output.Depth = output.hPosition.z;
77
78        return output;
79}
80//------------------------------------------------------------------------------------
81//
82// BumpPS: Bump Mapping pixel shader
83//
84//------------------------------------------------------------------------------------
85PS_OUTPUT BumpPS(VS_OUTPUT IN)
86{
87        PS_OUTPUT output;
88    // needs normalization because of linear interpolation
89    float3 View = normalize( IN.tView );
90    // needs normalization because of linear interpolation   
91    float3 Light = normalize( IN.tLight );
92    // get tangent-space normal from normal map
93    float3 Normal = tex2D(BumpMapSampler, IN.TexCoord).rgb;
94    // illumination calculation
95    output.Color = Illumination(Light, Normal, View, IN.TexCoord, Attenuation(IN.tLight));
96   
97    float blur = saturate(abs(IN.Depth - focalDist) * focalRange);
98    output.Depth = float4(IN.Depth, blur, 0, 0);
99
100    return output;
101}
102//------------------------------------------------------------------------------------
103// Technique definitions
104//------------------------------------------------------------------------------------
105technique BumpMapping
106{                                                                                                       
107    pass p0                                                                                     
108    {                                                                                           
109            VertexShader = compile vs_3_0 BumpVS();     
110            PixelShader  = compile ps_3_0 BumpPS();     
111        }                                                                                               
112}
Note: See TracBrowser for help on using the repository browser.