[1049] | 1 | float4x4 world_IT;
|
---|
| 2 |
|
---|
| 3 | struct VertOut
|
---|
| 4 | {
|
---|
| 5 | half4 hPosition :POSITION;
|
---|
| 6 | half2 texCoord :TEXCOORD;
|
---|
| 7 | half3 wPosition :TEXCOORD1;
|
---|
| 8 | half3 Normal :TEXCOORD2;
|
---|
| 9 | half3 Tangent : TEXCOORD3; // model space tangent vector |
---|
| 10 | half3 Binormal : TEXCOORD4; // model space binormal vector
|
---|
| 11 | };
|
---|
| 12 |
|
---|
| 13 | VertOut deaultVS(half4 position : POSITION,
|
---|
| 14 | half3 normal:NORMAL,
|
---|
| 15 | half3 Tangent : TEXCOORD1,
|
---|
| 16 | half2 texCoord : TEXCOORD0,
|
---|
| 17 | uniform float4x4 worldViewProj,
|
---|
| 18 | uniform float4x4 world)
|
---|
| 19 | {
|
---|
| 20 | VertOut OUT;
|
---|
| 21 | OUT.hPosition = mul(worldViewProj, position);
|
---|
| 22 | OUT.texCoord = texCoord;
|
---|
| 23 | OUT.wPosition = mul(world, position).xyz;
|
---|
| 24 | OUT.Normal = normal;
|
---|
| 25 | OUT.Tangent = Tangent;
|
---|
| 26 | OUT.Binormal = cross(Tangent, normal);
|
---|
| 27 | return OUT;
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | half4 deaultPS(VertOut IN,
|
---|
| 31 | uniform sampler2D Texture : register(s0),
|
---|
| 32 | uniform sampler2D NormalMap : register(s1),
|
---|
| 33 | uniform half3 lightPosition,
|
---|
| 34 | uniform half3 cameraPos,
|
---|
| 35 | uniform half4 ambientColor,
|
---|
| 36 | uniform half4 diffuseColor,
|
---|
| 37 | uniform half4 specularColor,
|
---|
| 38 | uniform half shininess
|
---|
| 39 | ):COLOR
|
---|
| 40 | {
|
---|
| 41 | half4 Color = half4(1,1,1,1);
|
---|
| 42 |
|
---|
| 43 | ///get normal
|
---|
| 44 | float3x3 ModelToTangent = float3x3(IN.Tangent, IN.Binormal, IN.Normal);
|
---|
| 45 | //float3x3 ModelToTangent = TransfModelToTangent(IN.Tangent, IN.Binormal, IN.Normal ); |
---|
| 46 | half3 tNormal = tex2D(NormalMap, IN.texCoord).rgb; |
---|
| 47 |
|
---|
| 48 |
|
---|
| 49 | half3 wNormal =mul(tNormal, ModelToTangent );
|
---|
| 50 | //wNormal = IN.Normal;
|
---|
| 51 | wNormal = normalize(mul( wNormal, world_IT ));
|
---|
| 52 |
|
---|
| 53 | ///shading
|
---|
| 54 |
|
---|
| 55 | half3 V = -normalize( cameraPos - IN.wPosition);
|
---|
| 56 | half3 light = lightPosition;
|
---|
| 57 | half3 L = normalize(light);
|
---|
| 58 | half3 H = normalize(L + V);
|
---|
| 59 | half4 lighting = lit(dot(wNormal, L),dot(wNormal, H), shininess);
|
---|
| 60 |
|
---|
| 61 | Color = tex2D(Texture, IN.texCoord) * (lighting.y * diffuseColor + ambientColor)
|
---|
| 62 | + lighting.z * specularColor;
|
---|
| 63 | //Color = float4(wNormal,1);
|
---|
| 64 | return Color;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 | half4 doubleTexturePS(VertOut IN,
|
---|
| 69 | uniform sampler2D baseTexture : register(s0),
|
---|
| 70 | uniform sampler2D paintTexture : register(s1),
|
---|
| 71 | uniform sampler2D NormalMap : register(s2),
|
---|
| 72 | uniform half3 lightPosition,
|
---|
| 73 | uniform half3 cameraPos,
|
---|
| 74 | uniform half4 ambientColor,
|
---|
| 75 | uniform half4 diffuseColor,
|
---|
| 76 | uniform half4 specularColor,
|
---|
| 77 | uniform half shininess,
|
---|
| 78 | uniform float2 texUVmult
|
---|
| 79 | ):COLOR
|
---|
| 80 | {
|
---|
| 81 | half4 Color = half4(1,1,1,1);
|
---|
| 82 |
|
---|
| 83 | float2 baseTexCoord = IN.texCoord * texUVmult;
|
---|
| 84 |
|
---|
| 85 | ///get normal
|
---|
| 86 | float3x3 ModelToTangent = float3x3(IN.Tangent, IN.Binormal, IN.Normal);
|
---|
| 87 | //float3x3 ModelToTangent = TransfModelToTangent(IN.Tangent, IN.Binormal, IN.Normal ); |
---|
| 88 | half3 tNormal = tex2D(NormalMap, baseTexCoord).rgb; |
---|
| 89 |
|
---|
| 90 |
|
---|
| 91 | half3 wNormal =mul(tNormal, ModelToTangent );
|
---|
| 92 | //wNormal = IN.Normal;
|
---|
| 93 | wNormal = normalize(mul( wNormal, world_IT ));
|
---|
| 94 |
|
---|
| 95 | ///shading
|
---|
| 96 |
|
---|
| 97 | half3 V = -normalize( cameraPos - IN.wPosition);
|
---|
| 98 | half3 light = lightPosition;
|
---|
| 99 | half3 L = normalize(light);
|
---|
| 100 | half3 H = normalize(L + V);
|
---|
| 101 | half4 lighting = lit(dot(wNormal, L),dot(wNormal, H), shininess);
|
---|
| 102 |
|
---|
| 103 | float4 baseColor = tex2D(baseTexture, baseTexCoord);
|
---|
| 104 | float4 paintColor = tex2D(paintTexture, IN.texCoord);
|
---|
| 105 | float4 texColor = baseColor + paintColor;
|
---|
| 106 |
|
---|
| 107 | Color = texColor * (lighting.y * diffuseColor + ambientColor)
|
---|
| 108 | + lighting.z * specularColor;
|
---|
| 109 | //Color = float4(wNormal,1);
|
---|
| 110 | return Color;
|
---|
| 111 | } |
---|