Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This is used by 3dsmax to load the correct parser
- string ParamID = "0x0";
- // light directions (world space)
- uniform extern float3 lightPos1 : Position <
- string UIName = "Light Direction 1";
- string Object = "omnilight";
- int RefID = 0;
- > = {-0.577, -0.577, 0.577};
- float3 lightPos2 : Position <
- string UIName = "Light Direction 2";
- string Object = "OmniLight";
- int RefID = 1;
- > = {-0.577, -0.577, 0.577};
- float3 lightPos3 : Position <
- string UIName = "Light Direction 3";
- string Object = "OmniLight";
- int RefID = 2;
- > = {-0.577, -0.577, 0.577};
- float warpWeight <
- string UIName = "Warp Weight";
- string UIType = "FloatSpinner";
- float UIMin = 0.0f;
- float UIMax = 1.0f;
- > = 0.75f;
- // material values
- float4 k_d <
- string UIName = "Diffuse";
- > = float4( 0.47f, 0.47f, 0.47f, 1.0f ); // diffuse
- float d<
- string UIName = " Diffuse Power";
- string UIType = "FloatSpinner";
- float UIMin = 0.0f;
- float UIMax = 100.0f;
- > = 1;
- bool bDiffuse <
- string UIName = "Use Diffuse Map";
- string UIType = "Checkbox";
- > = false;
- // diffuse texture passed in:
- texture diffuseMap : DIFFUSEMAP
- <
- string name ="";
- string UIName = " Diffuse Map";
- >;
- float4 k_s <
- string UIName = "Specular";
- > = float4( 0.47f, 0.47f, 0.47f, 1.0f ); // specular
- float specPower <
- string UIName = " Specular Power";
- string UIType = "FloatSpinner";
- float UIMin = 0.0f;
- float UIMax = 100.0f;
- > = 50;
- bool bSpecular <
- string UIName = "Use Specular Map";
- string UIType = "Checkbox";
- > = false;
- // diffuse texture passed in:
- texture specularMap : SPECULARMAP
- <
- string name ="";
- string UIName = " Specular Map";
- >;
- bool bNormal <
- string UIName = "Use Normal Map";
- string UIType = "Checkbox";
- > = false;
- // normal texture passed in:
- texture normalMap : NORMALMAP
- <
- string name ="";
- string UIName = " Normal Map";
- >;
- // samplers for our textures:
- sampler2D diffuseSampler = sampler_state
- {
- Texture = <diffuseMap>;
- MinFilter=LINEAR;
- MagFilter=LINEAR;
- MipFilter=LINEAR;
- MipLODBias=-1;
- AddressU = WRAP;
- AddressV = WRAP;
- };
- sampler2D specSampler = sampler_state
- {
- Texture = <specularMap>;
- MinFilter=LINEAR;
- MagFilter=LINEAR;
- MipFilter=LINEAR;
- MipLODBias=-1;
- AddressU = WRAP;
- AddressV = WRAP;
- };
- sampler2D normalSampler = sampler_state
- {
- Texture = <normalMap>;
- MinFilter=LINEAR;
- MagFilter=LINEAR;
- MipFilter=LINEAR;
- MipLODBias=-1;
- AddressU = WRAP;
- AddressV = WRAP;
- };
- // transformations
- float4x4 World : WORLD;
- float4x4 View : VIEW;
- float4x4 Projection : PROJECTION;
- float4x4 ViewInv : ViewInverse;
- float4x4 WorldViewProj : WORLDVIEWPROJ;
- float4x4 WorldView : WORLDVIEW;
- struct VS_OUTPUT
- {
- float4 Pos : POSITION;
- float3 normal : TEXCOORD0;
- float3 tangent : TEXCOORD1;
- float3 binormal : TEXCOORD2;
- float3 light : TEXCOORD3;
- float3 eyeVec : TEXCOORD4;
- float3 half : TEXCOORD5;
- float2 Tex : TEXCOORD6;
- };
- // vertex shader
- VS_OUTPUT VS(
- float3 Pos : POSITION,
- float3 col : COLOR,
- float3 Norm : NORMAL,
- float3 Tangent : TANGENT,
- float3 Binormal : BINORMAL,
- float2 Tex : TEXCOORD0,
- uniform float3 lightPos )
- {
- VS_OUTPUT Out = (VS_OUTPUT)0;
- float3 P = mul(float4(Pos, 1),(float4x4)World).rgb; // position (from object to world space)
- float3 L = normalize(lightPos - P);
- Out.normal = normalize(mul(Norm, (float3x3)World)); // normal (from object to world space)
- Out.tangent = normalize(mul(Tangent, (float3x3)World)); // normal (from object to world space)
- Out.binormal = normalize(mul(Binormal, (float3x3)World)); // normal (from object to world space)
- Out.light = normalize(L);
- Out.eyeVec = normalize(ViewInv[3].xyz - P); //calculate eyevector
- Out.half = (Out.light + Out.eyeVec);
- float distToCam = length(ViewInv[3].xyz - P);
- Out.Pos = mul(float4(Pos,1),WorldViewProj); // position (projected)
- Out.Pos.xy *= lerp( 1, Out.Pos.z / max(distToCam, 1.f), min(warpWeight,0.99f));
- Out.Tex = Tex;
- return Out;
- }
- // pixel shader
- float4 PS(
- VS_OUTPUT input, uniform bool bAdditive ) : COLOR
- {
- float3 normal = normalize( input.normal.rgb );
- float3 light = normalize( input.light.rgb );
- float3 half = normalize( input.half );
- float4 color = 0;
- // Sample the normal map and convert it to a proper normal vector:
- float4 normalTex = float4( normal, 1 );
- if (bNormal)
- {
- // Sample normals:
- normalTex = tex2D(normalSampler, input.Tex);
- normalTex = (2*normalTex)-1;
- normalTex.xyz = normalTex.yxz;
- // Create a tangent space matrix:
- const float3x3 basis = float3x3( normalize( input.tangent ), normalize( input.binormal ), normalize( input.normal ) );
- normalTex.rgb = normalize( mul(normalTex.rgb, basis) );
- }
- float4 diffuse = k_d;
- if (bDiffuse)
- {
- diffuse *= tex2D(diffuseSampler, input.Tex);
- }
- float4 specular = k_s;
- if (bSpecular)
- specular *= tex2D(specSampler, input.Tex);
- float lambert = pow( saturate(dot(normalTex, light)), d ); // LAMBERT
- float blinn = pow( saturate(dot(normalTex, half) ), specPower ); // BLINN
- color += saturate(lambert * diffuse) + (blinn * specular);
- color.a = 1;
- return color;
- }
- technique ThreeLight
- {
- pass P0
- {
- // shaders
- CullMode = None;
- VertexShader = compile vs_3_0 VS(lightPos1);
- PixelShader = compile ps_3_0 PS(false);
- }
- pass P1
- {
- // shaders
- CullMode = None;
- AlphaBlendEnable = true;
- srcblend = one;
- destblend = one;
- VertexShader = compile vs_3_0 VS(lightPos2);
- PixelShader = compile ps_3_0 PS(true);
- }
- pass P2
- {
- // shaders
- CullMode = None;
- AlphaBlendEnable = true;
- SrcBlend = one;
- DestBlend = one;
- VertexShader = compile vs_3_0 VS(lightPos3);
- PixelShader = compile ps_3_0 PS(true);
- }
- }
- technique TwoLight
- {
- pass P0
- {
- // shaders
- CullMode = None;
- VertexShader = compile vs_3_0 VS(lightPos1);
- PixelShader = compile ps_3_0 PS(false);
- }
- pass P1
- {
- // shaders
- CullMode = None;
- AlphaBlendEnable = true;
- srcblend = one;
- destblend = one;
- VertexShader = compile vs_3_0 VS(lightPos2);
- PixelShader = compile ps_3_0 PS(true);
- }
- }
- technique OneLight
- {
- pass P0
- {
- // shaders
- CullMode = None;
- VertexShader = compile vs_3_0 VS(lightPos1);
- PixelShader = compile ps_3_0 PS(false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement