0001:
0002:
0003:
0004:
0005:
0006: #include "paraboloid.fx"
0007:
0008:
0009:
0010:
0011: float4x4 mWVP;
0012: float4x4 mWV;
0013: float4x4 mW;
0014: float4 vEye;
0015:
0016: float MAP_WIDTH;
0017: float MAP_HEIGHT;
0018:
0019:
0020:
0021:
0022: texture SrcTex;
0023: sampler SrcSamp = sampler_state
0024: {
0025: Texture = <SrcTex>;
0026: MinFilter = LINEAR;
0027: MagFilter = LINEAR;
0028: MipFilter = NONE;
0029:
0030: AddressU = Clamp;
0031: AddressV = Clamp;
0032: };
0033:
0034: texture DecaleTex;
0035: sampler DecaleSamp = sampler_state
0036: {
0037: Texture = <DecaleTex>;
0038: MinFilter = LINEAR;
0039: MagFilter = LINEAR;
0040: MipFilter = NONE;
0041:
0042: AddressU = Clamp;
0043: AddressV = Clamp;
0044: };
0045:
0046:
0047:
0048: texture ParaboloidFrontTex;
0049: sampler ParaboloidFrontSamp = sampler_state
0050: {
0051: Texture = <ParaboloidFrontTex>;
0052: MinFilter = LINEAR;
0053: MagFilter = LINEAR;
0054: MipFilter = NONE;
0055:
0056: AddressU = Clamp;
0057: AddressV = Clamp;
0058: };
0059:
0060: texture ParaboloidBackTex;
0061: sampler ParaboloidBackSamp = sampler_state
0062: {
0063: Texture = <ParaboloidBackTex>;
0064: MinFilter = LINEAR;
0065: MagFilter = LINEAR;
0066: MipFilter = NONE;
0067:
0068: AddressU = Clamp;
0069: AddressV = Clamp;
0070: };
0071:
0072:
0073:
0074:
0075:
0076: struct VS_OUTPUT
0077: {
0078: float4 Pos : POSITION;
0079: float4 Color : COLOR0;
0080: float2 Tex0 : TEXCOORD0;
0081: float2 Tex1 : TEXCOORD1;
0082: float3 Normal : TEXCOORD2;
0083: float2 DecaleTex : TEXCOORD3;
0084: };
0085:
0086:
0087:
0088:
0089: VS_OUTPUT VS (
0090: float4 Pos : POSITION
0091: ,float4 Normal : NORMAL
0092: ,float4 Tex0 : TEXCOORD0
0093: ){
0094: VS_OUTPUT Out = (VS_OUTPUT)0;
0095:
0096:
0097: Out.Pos = mul( Pos, mWVP );
0098:
0099:
0100: Out.Tex0 = Tex0;
0101:
0102: return Out;
0103: }
0104:
0105:
0106:
0107:
0108:
0109:
0110:
0111: float4 PS (VS_OUTPUT In) : COLOR
0112: {
0113: float4 Out;
0114:
0115:
0116: Out = tex2D( SrcSamp, In.Tex0 );
0117:
0118: return Out;
0119: }
0120:
0121:
0122:
0123:
0124:
0125:
0126:
0127:
0128: VS_OUTPUT VS_Parabploid (
0129: float4 Pos : POSITION
0130: ){
0131: VS_OUTPUT Out = (VS_OUTPUT)0;
0132:
0133:
0134: Out.Pos = paraboloid( Pos, mWV );
0135:
0136:
0137: Out.Tex0.x = + 0.5 * Pos.x + 0.5;
0138: Out.Tex0.y = - 0.5 * Pos.y + 0.5;
0139:
0140: return Out;
0141: }
0142:
0143:
0144:
0145:
0146:
0147: VS_OUTPUT VS_Envmap (
0148: float4 Pos : POSITION
0149: , float4 Normal : NORMAL
0150: , float2 Tex : TEXCOORD0
0151: )
0152: {
0153: VS_OUTPUT Out = (VS_OUTPUT)0;
0154: float3 ray;
0155: float3 ref;
0156:
0157:
0158: Out.Pos = mul( Pos, mWVP );
0159:
0160:
0161: Out.Color = 0.0f;
0162:
0163:
0164: ray = normalize( Pos - vEye ).xyz;
0165: ref = reflect( ray, Normal.xyz );
0166: ref = mul( ref, mW );
0167:
0168: Out.Tex0.x = 0.5 * ( 1 + ref.x/(1+ref.z));
0169: Out.Tex0.y = 0.5 * ( 1 - ref.y/(1+ref.z));
0170: Out.Tex1.x = 0.5 * ( 1 - ref.x/(1-ref.z));
0171: Out.Tex1.y = 0.5 * ( 1 - ref.y/(1-ref.z));
0172:
0173: Out.Color.w = ref.z + 0.5f;
0174:
0175:
0176: Out.Normal = mul( Normal.xyz, mWV );
0177:
0178: Out.DecaleTex = Tex;
0179:
0180: return Out;
0181: }
0182:
0183:
0184:
0185:
0186:
0187: float4 GetEnvMap( float2 tex_front, float2 tex_back, float NE, bool front_or_back )
0188: {
0189: float4 env;
0190:
0191: if( front_or_back ){
0192: env = tex2D( ParaboloidFrontSamp, tex_front );
0193: }else{
0194: env = tex2D( ParaboloidBackSamp, tex_back );
0195: }
0196:
0197:
0198: float F = 0.1 + 1.0 * pow(1+NE, 4);
0199:
0200: return F * env;
0201: }
0202:
0203:
0204:
0205:
0206: float4 PS_Envmap (VS_OUTPUT In) : COLOR
0207: {
0208: float4 Env = GetEnvMap( In.Tex0, In.Tex1, In.Normal.z, 0.5 < In.Color.w );
0209: float4 decale = tex2D( DecaleSamp, In.DecaleTex );
0210:
0211: return 0.6 * decale + Env;
0212: }
0213:
0214:
0215:
0216:
0217:
0218:
0219:
0220:
0221:
0222: technique TShader
0223: {
0224: pass P0
0225: {
0226: VertexShader = compile vs_1_1 VS();
0227: PixelShader = compile ps_1_1 PS();
0228: }
0229:
0230: pass P1
0231: {
0232: VertexShader = compile vs_1_1 VS_Parabploid();
0233: PixelShader = compile ps_1_1 PS();
0234: }
0235:
0236: pass P2
0237: {
0238: VertexShader = compile vs_1_1 VS_Envmap();
0239: PixelShader = compile ps_2_0 PS_Envmap();
0240: }
0241: }
0242: