Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //NormalMapping.fx
- //FirstName: Igor
- //LastName: Vermeulen
- //Class 2DAE_GD05
- //GLOBAL VARIABLES
- //****************
- float4x4 gMatrixWorldViewProj : WORLDVIEWPROJECTION;
- float4x4 gMatrixWorld: WORLD;
- float4 gColorAmbient: COLOR = float4(1.0,1.0,1.0,1.0);
- float gAmbientIntensity<
- string UIName = "Ambient Intensity";
- string UIWidget = "Slider";
- float UIMin = 0.0;
- float UIMax = 1.0;
- float UIStep = 0.01;
- > = 0.0f;
- //Diffuse Map Variables
- Texture2D gTextureDiffuse<
- string UIName = "Diffuse Texture";
- string ResourceName = "CobbleStone Textures/CobbleStone_DiffuseMap.dds";
- string ResourceType = "2D";
- >;
- //Light
- float3 gLightDirection: DIRECTION<
- string UIName = "Light Direction";
- string Object = "TargetLight";
- > = float3 (-0.57 , -0.57, 0.57);
- float4 gColorDiffuse : COLOR = float4(1.0, 1.0, 1.0, 1.0);
- //Normal map Variables
- Texture2D m_normalMapTexture <
- string UIName = "Normal Map";
- string ResourceName = "CobbleStone Textures/CobbleStone_NormalMap.dds";
- string ResourceType = "2D";
- >;
- SamplerState m_NormalMapSampler
- {
- Filter = MIN_MAG_MIP_POINT;
- AddressU = WRAP;
- AddressV = WRAP;
- };
- //STATES
- //******
- RasterizerState DisableCulling { CullMode = NONE; };
- SamplerState gDiffuseSamplerState
- {
- Filter = MIN_MAG_MIP_LINEAR;
- AddressU = WRAP;
- AddressV = WRAP;
- };
- struct VS_INPUT
- {
- float3 Position: POSITION;
- float3 Normal: NORMAL;
- float2 TexCoord: TEXCOORD0;
- float3 tangent : TANGENT;
- };
- struct VS_OUTPUT
- {
- float4 Position: SV_POSITION;
- float3 Normal: NORMAL;
- float2 TexCoord: TEXCOORD0;
- float3 tangent : TANGENT;
- };
- //MAIN VERTEX SHADER
- //******************
- VS_OUTPUT MainVS(VS_INPUT input)
- {
- VS_OUTPUT output = (VS_OUTPUT)0;
- output.Position = mul(
- float4(input.Position,1.0),
- gMatrixWorldViewProj );
- output.Normal = normalize(mul(
- input.Normal,
- (float3x3)gMatrixWorld));
- output.TexCoord = input.TexCoord;
- output.tangent = normalize(mul(input.tangent,
- (float3x3)gMatrixWorld));
- return output;
- }
- //MAIN PIXEL SHADER
- //*****************
- float4 MainPS(VS_OUTPUT input) : SV_TARGET {
- float3 normal = normalize(input.Normal);
- float3 tangent = normalize(input.tangent);
- //
- float3 binormal = normalize(cross(tangent,normal));
- //
- float3x3 localAxis = {tangent,
- binormal,
- normal};
- //
- float3 sampledNormal = m_normalMapTexture.Sample(gDiffuseSamplerState, input.TexCoord);
- sampledNormal.x = (sampledNormal.x *2) -1;
- sampledNormal.y = (sampledNormal.y *2) -1;
- sampledNormal.z = (sampledNormal.z *2) -1;
- float3 newNormal = mul(sampledNormal,localAxis);
- //
- float4 finalColor = gTextureDiffuse.Sample(
- gDiffuseSamplerState, input.TexCoord);
- float diffuseIntensity = dot( newNormal, -gLightDirection);
- diffuseIntensity = saturate(diffuseIntensity);
- finalColor *= diffuseIntensity;
- finalColor += gColorAmbient * gAmbientIntensity;
- return finalColor;
- }
- //TECHNIQUES
- //**********
- technique10 DefaultTechnique {
- pass p0 {
- SetRasterizerState(DisableCulling);
- SetVertexShader(CompileShader(vs_4_0, MainVS()));
- SetPixelShader(CompileShader(ps_4_0, MainPS()));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement