[954] | 1 |
|
---|
| 2 | // This is used by 3dsmax to load the correct parser
|
---|
| 3 | string ParamID = "0x0";
|
---|
| 4 |
|
---|
| 5 | //DxMaterial specific
|
---|
| 6 |
|
---|
| 7 | // light direction (view space)
|
---|
| 8 | float3 g_LightDir : Direction <
|
---|
| 9 | string UIName = "Light";
|
---|
| 10 | string Object = "TargetLight";
|
---|
| 11 | int refID = 0;
|
---|
| 12 | > = {-0.577, -0.577, 0.577};
|
---|
| 13 |
|
---|
| 14 | float4 g_LightCol : LIGHTCOLOR
|
---|
| 15 | <
|
---|
| 16 | int LightRef = 0;
|
---|
| 17 | > = float4(0.0f, 0.0f, 0.0f, 0.0f);
|
---|
| 18 |
|
---|
| 19 | // material reflectivity
|
---|
| 20 | float4 k_a <
|
---|
| 21 | string UIName = "Ambient";
|
---|
| 22 | > = float4( 0.47f, 0.47f, 0.47f, 1.0f ); // ambient
|
---|
| 23 |
|
---|
| 24 | float4 k_d <
|
---|
| 25 | string UIName = "Diffuse";
|
---|
| 26 | > = float4( 0.47f, 0.47f, 0.47f, 1.0f ); // diffuse
|
---|
| 27 |
|
---|
| 28 | float4 k_s <
|
---|
| 29 | string UIName = "Specular";
|
---|
| 30 | > = float4( 1.0f, 1.0f, 1.0f, 1.0f ); // diffuse // specular
|
---|
| 31 |
|
---|
| 32 | int n<
|
---|
| 33 | string UIName = "Specular Power";
|
---|
| 34 | string UIType = "IntSpinner";
|
---|
| 35 | float UIMin = 0.0f;
|
---|
| 36 | float UIMax = 50.0f;
|
---|
| 37 | > = 15;
|
---|
| 38 |
|
---|
| 39 | bool g_AlphaVertex <
|
---|
| 40 | string UIName = "Vertex Alpha";
|
---|
| 41 | > = true;
|
---|
| 42 |
|
---|
| 43 | bool g_AddVertexColor <
|
---|
| 44 | string UIName = "Add Vertex Color";
|
---|
| 45 | > =false;
|
---|
| 46 |
|
---|
| 47 | bool g_UseParallax <
|
---|
| 48 | string UIName = "Normal Map Parallax";
|
---|
| 49 | > =false;
|
---|
| 50 |
|
---|
| 51 | float g_BumpScale <
|
---|
| 52 | string UIName = "Bump Amount";
|
---|
| 53 | float UIMin = 0.0f;
|
---|
| 54 | float UIMax = 5.0f;
|
---|
| 55 | float UIStep = 0.01f;
|
---|
| 56 | > = 1.0f;
|
---|
| 57 |
|
---|
| 58 |
|
---|
| 59 | float g_ParallaxScale <
|
---|
| 60 | string UIName = "Parallax Scale";
|
---|
| 61 | float UIMin = -0.50f;
|
---|
| 62 | float UIMax = 0.5f;
|
---|
| 63 | float UIStep = 0.01f;
|
---|
| 64 | > = 0.02f;
|
---|
| 65 |
|
---|
| 66 | float g_ParallaxBias <
|
---|
| 67 | string UIName = "Parallax Bias";
|
---|
| 68 | float UIMin = -0.5f;
|
---|
| 69 | float UIMax = 0.5f;
|
---|
| 70 | float UIStep = 0.01f;
|
---|
| 71 | > = 0.0f;
|
---|
| 72 |
|
---|
| 73 | bool g_AmbientOccEnable <
|
---|
| 74 | string UIName = "Ambient Occlusion Enable";
|
---|
| 75 | > = false;
|
---|
| 76 |
|
---|
| 77 | texture g_AmbientOccTexture <
|
---|
| 78 | string UIName = "Ambient Occlusion";
|
---|
| 79 | int Texcoord = 4;
|
---|
| 80 | int MapChannel = 1;
|
---|
| 81 | >;
|
---|
| 82 |
|
---|
| 83 | bool g_TopDiffuseEnable <
|
---|
| 84 | string UIName = "Top Diffuse Color Enable";
|
---|
| 85 | > = false;
|
---|
| 86 |
|
---|
| 87 | float g_TopTextureScale <
|
---|
| 88 | string UIName = "Top Texture Scale";
|
---|
| 89 | float UIMin = 0.0001f;
|
---|
| 90 | float UIMax = 1000.0f;
|
---|
| 91 | float UIStep = 1.0f;
|
---|
| 92 | > = 1.0f;
|
---|
| 93 |
|
---|
| 94 | texture g_TopTexture : DiffuseMap<
|
---|
| 95 | string UIName = "Top Diffuse Map ";
|
---|
| 96 | int Texcoord = 0;
|
---|
| 97 | int MapChannel = 1;
|
---|
| 98 | >;
|
---|
| 99 |
|
---|
| 100 | bool g_BottomDiffuseEnable <
|
---|
| 101 | string UIName = "Bottom Diffuse Color Enable";
|
---|
| 102 | > = false;
|
---|
| 103 |
|
---|
| 104 | texture g_BottomTexture <
|
---|
| 105 | string UIName = "Bottom Diffuse";
|
---|
| 106 | int Texcoord = 5;
|
---|
| 107 | int MapChannel = 1;
|
---|
| 108 | >;
|
---|
| 109 |
|
---|
| 110 | bool g_SpecularEnable <
|
---|
| 111 | string UIName = "Specular Enable";
|
---|
| 112 | > = false;
|
---|
| 113 |
|
---|
| 114 | texture g_SpecularTexture <
|
---|
| 115 | string UIName = "Specular";
|
---|
| 116 | int Texcoord = 6;
|
---|
| 117 | int MapChannel = 1;
|
---|
| 118 | >;
|
---|
| 119 |
|
---|
| 120 | bool g_NormalEnable <
|
---|
| 121 | string UIName = "Normal Enable";
|
---|
| 122 | > = false;
|
---|
| 123 |
|
---|
| 124 | texture g_NormalTexture <
|
---|
| 125 | string UIName = "Normal";
|
---|
| 126 | int Texcoord = 7;
|
---|
| 127 | int MapChannel = 1;
|
---|
| 128 | >;
|
---|
| 129 |
|
---|
| 130 | bool g_ReflectionEnable <
|
---|
| 131 | string UIName = "Reflection Enable";
|
---|
| 132 | > = false;
|
---|
| 133 |
|
---|
| 134 | texture g_ReflectionTexture <
|
---|
| 135 | string UIName = "Reflection";
|
---|
| 136 | string Type = "CUBE";
|
---|
| 137 | >;
|
---|
| 138 |
|
---|
| 139 |
|
---|
| 140 | sampler2D g_AmbientOccSampler = sampler_state
|
---|
| 141 | {
|
---|
| 142 | Texture = <g_AmbientOccTexture>;
|
---|
| 143 | MinFilter = Linear;
|
---|
| 144 | MagFilter = Linear;
|
---|
| 145 | MipFilter = Linear;
|
---|
| 146 | };
|
---|
| 147 |
|
---|
| 148 |
|
---|
| 149 | sampler2D g_TopSampler = sampler_state
|
---|
| 150 | {
|
---|
| 151 | Texture = <g_TopTexture>;
|
---|
| 152 | MinFilter = Linear;
|
---|
| 153 | MagFilter = Linear;
|
---|
| 154 | MipFilter = Linear;
|
---|
| 155 | };
|
---|
| 156 |
|
---|
| 157 | sampler2D g_BottomSampler = sampler_state
|
---|
| 158 | {
|
---|
| 159 | Texture = <g_BottomTexture>;
|
---|
| 160 | MinFilter = Linear;
|
---|
| 161 | MagFilter = Linear;
|
---|
| 162 | MipFilter = Linear;
|
---|
| 163 | };
|
---|
| 164 |
|
---|
| 165 | sampler2D g_SpecularSampler = sampler_state
|
---|
| 166 | {
|
---|
| 167 | Texture = <g_SpecularTexture>;
|
---|
| 168 | MinFilter = Linear;
|
---|
| 169 | MagFilter = Linear;
|
---|
| 170 | MipFilter = Linear;
|
---|
| 171 | };
|
---|
| 172 |
|
---|
| 173 | sampler2D g_NormalSampler = sampler_state
|
---|
| 174 | {
|
---|
| 175 | Texture = <g_NormalTexture>;
|
---|
| 176 | MinFilter = Linear;
|
---|
| 177 | MagFilter = Linear;
|
---|
| 178 | MipFilter = Linear;
|
---|
| 179 | };
|
---|
| 180 |
|
---|
| 181 | samplerCUBE g_ReflectionSampler = sampler_state
|
---|
| 182 | {
|
---|
| 183 | Texture = <g_ReflectionTexture>;
|
---|
| 184 | MinFilter = Linear;
|
---|
| 185 | MagFilter = Linear;
|
---|
| 186 | MipFilter = Linear;
|
---|
| 187 | };
|
---|
| 188 |
|
---|
| 189 |
|
---|
| 190 |
|
---|
| 191 | // transformations
|
---|
| 192 | float4x4 World : WORLD;
|
---|
| 193 | float4x4 View : VIEW;
|
---|
| 194 | float4x4 Projection : PROJECTION;
|
---|
| 195 | float4x4 WorldViewProj : WORLDVIEWPROJ;
|
---|
| 196 | float4x4 WorldView : WORLDVIEW;
|
---|
| 197 | float3 g_CamPos : WORLDCAMERAPOSITION;
|
---|
| 198 |
|
---|
| 199 | int texcoord1 : Texcoord
|
---|
| 200 | <
|
---|
| 201 | int Texcoord = 1;
|
---|
| 202 | int MapChannel = 0;
|
---|
| 203 | >;
|
---|
| 204 |
|
---|
| 205 | int texcoord2 : Texcoord
|
---|
| 206 | <
|
---|
| 207 | int Texcoord = 2;
|
---|
| 208 | int MapChannel = -2;
|
---|
| 209 | >;
|
---|
| 210 |
|
---|
| 211 | int texcoord3 : Texcoord
|
---|
| 212 | <
|
---|
| 213 | int Texcoord = 3;
|
---|
| 214 | int MapChannel = -1;
|
---|
| 215 | >;
|
---|
| 216 |
|
---|
| 217 |
|
---|
| 218 | float3 NormalCalc(float3 mapNorm, float BumpScale)
|
---|
| 219 | {
|
---|
| 220 | float3 v = {0.5f,0.5f,1.0f};
|
---|
| 221 | mapNorm = lerp(v, mapNorm, BumpScale );
|
---|
| 222 | mapNorm = ( mapNorm * 2.0f ) - 1.0f;
|
---|
| 223 | return mapNorm;
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 |
|
---|
| 227 | struct VSIn
|
---|
| 228 | {
|
---|
| 229 | float3 Position : POSITION;
|
---|
| 230 | float3 Normal : NORMAL;
|
---|
| 231 | float3 Tangent : TANGENT;
|
---|
| 232 | float3 BiNormal : BINORMAL;
|
---|
| 233 | float2 UV0 : TEXCOORD0;
|
---|
| 234 | float3 Colour : TEXCOORD1;
|
---|
| 235 | float3 Alpha : TEXCOORD2;
|
---|
| 236 | float3 Illum : TEXCOORD3;
|
---|
| 237 | float3 UV1 : TEXCOORD4;
|
---|
| 238 | float3 UV2 : TEXCOORD5;
|
---|
| 239 | float3 UV3 : TEXCOORD6;
|
---|
| 240 | float3 UV4 : TEXCOORD7;
|
---|
| 241 |
|
---|
| 242 | };
|
---|
| 243 |
|
---|
| 244 |
|
---|
| 245 | struct VSOut
|
---|
| 246 | {
|
---|
| 247 | float4 Position : POSITION;
|
---|
| 248 | float4 Colour : COLOR0;
|
---|
| 249 | float2 UV0 : TEXCOORD0;
|
---|
| 250 | float3 LightDir : TEXCOORD1;
|
---|
| 251 | float3 Normal : TEXCOORD2;
|
---|
| 252 | float3 ViewDir : TEXCOORD3;
|
---|
| 253 | float2 UV1 : TEXCOORD4;
|
---|
| 254 | float2 UV2 : TEXCOORD5;
|
---|
| 255 | float2 UV3 : TEXCOORD6;
|
---|
| 256 | float2 UV4 : TEXCOORD7;
|
---|
| 257 |
|
---|
| 258 | };
|
---|
| 259 |
|
---|
| 260 | struct PSIn
|
---|
| 261 | {
|
---|
| 262 | float4 Colour : COLOR0;
|
---|
| 263 | float2 UV0 : TEXCOORD0;
|
---|
| 264 | float3 LightDir : TEXCOORD1;
|
---|
| 265 | float3 Normal : TEXCOORD2;
|
---|
| 266 | float3 ViewDir : TEXCOORD3;
|
---|
| 267 | float2 UV1 : TEXCOORD4;
|
---|
| 268 | float2 UV2 : TEXCOORD5;
|
---|
| 269 | float2 UV3 : TEXCOORD6;
|
---|
| 270 | float2 UV4 : TEXCOORD7;
|
---|
| 271 |
|
---|
| 272 | };
|
---|
| 273 |
|
---|
| 274 | struct PSOut
|
---|
| 275 | {
|
---|
| 276 | float4 Colour : COLOR0;
|
---|
| 277 | };
|
---|
| 278 |
|
---|
| 279 |
|
---|
| 280 | VSOut VS(VSIn vsIn)
|
---|
| 281 | {
|
---|
| 282 | VSOut vsOut;
|
---|
| 283 | vsOut.Position = mul(float4(vsIn.Position, 1.0f), WorldViewProj);
|
---|
| 284 | vsOut.Colour.rgb = vsIn.Colour * vsIn.Illum;
|
---|
| 285 | vsOut.Colour.a = vsIn.Alpha.x;
|
---|
| 286 | vsOut.Normal = vsIn.Normal;
|
---|
| 287 |
|
---|
| 288 | float4 WorldPos = mul(float4(vsIn.Position, 1.0f),World);
|
---|
| 289 | float3 ViewDir = g_CamPos - WorldPos.xyz;
|
---|
| 290 |
|
---|
| 291 | if(g_NormalEnable)
|
---|
| 292 | {
|
---|
| 293 | float3x3 objToTangent;
|
---|
| 294 |
|
---|
| 295 | objToTangent[0] = vsIn.BiNormal;
|
---|
| 296 | objToTangent[1] = vsIn.Tangent;
|
---|
| 297 | objToTangent[2] = vsIn.Normal;
|
---|
| 298 |
|
---|
| 299 | vsOut.LightDir = mul(objToTangent, g_LightDir);
|
---|
| 300 | vsOut.ViewDir = mul(objToTangent, ViewDir);
|
---|
| 301 |
|
---|
| 302 | }
|
---|
| 303 | else
|
---|
| 304 | {
|
---|
| 305 | vsOut.LightDir = g_LightDir;
|
---|
| 306 | vsOut.ViewDir = ViewDir;
|
---|
| 307 | }
|
---|
| 308 |
|
---|
| 309 | vsOut.UV0 = vsIn.UV0;
|
---|
| 310 | vsOut.UV1 = vsIn.UV1;
|
---|
| 311 | vsOut.UV2 = vsIn.UV2;
|
---|
| 312 | vsOut.UV3 = vsIn.UV3;
|
---|
| 313 | vsOut.UV4 = vsIn.UV4;
|
---|
| 314 | return vsOut;
|
---|
| 315 | }
|
---|
| 316 |
|
---|
| 317 | PSOut PS( PSIn psIn )
|
---|
| 318 | {
|
---|
| 319 | PSOut psOut;
|
---|
| 320 | float3 BottomCol = k_d.rgb;
|
---|
| 321 | float4 TopCol = k_d;
|
---|
| 322 | float3 LightCol = float3(1.0,1.0,1.0);
|
---|
| 323 | float3 Normal = normalize(psIn.Normal);
|
---|
| 324 | float3 LightDir = normalize(psIn.LightDir);
|
---|
| 325 | float3 ViewDir = normalize(psIn.ViewDir);
|
---|
| 326 | float3 Ambient = k_a.rgb;
|
---|
| 327 | float3 SpecLevel = float3(1.0,1.0,1.0);
|
---|
| 328 | float Alpha;
|
---|
| 329 |
|
---|
| 330 | float2 normalUV = psIn.UV4;
|
---|
| 331 |
|
---|
| 332 | float4 newCol;
|
---|
| 333 |
|
---|
| 334 | if(g_AmbientOccEnable)
|
---|
| 335 | Ambient *= tex2D(g_AmbientOccSampler, psIn.UV1);
|
---|
| 336 |
|
---|
| 337 |
|
---|
| 338 | if(g_TopDiffuseEnable)
|
---|
| 339 | TopCol = tex2D(g_TopSampler, psIn.UV0 * g_TopTextureScale);
|
---|
| 340 |
|
---|
| 341 | if(g_BottomDiffuseEnable)
|
---|
| 342 | BottomCol = tex2D(g_BottomSampler, psIn.UV2);
|
---|
| 343 |
|
---|
| 344 |
|
---|
| 345 | if(g_AlphaVertex)
|
---|
| 346 | Alpha = psIn.Colour.a;
|
---|
| 347 | else
|
---|
| 348 | Alpha = TopCol.a;
|
---|
| 349 |
|
---|
| 350 | if(g_UseParallax)
|
---|
| 351 | {
|
---|
| 352 | float height = tex2D(g_NormalSampler, psIn.UV4 ).a;
|
---|
| 353 | float Altitude = height + g_ParallaxBias;
|
---|
| 354 | normalUV = Altitude * g_ParallaxScale*ViewDir;
|
---|
| 355 | normalUV += psIn.UV4;
|
---|
| 356 | }
|
---|
| 357 |
|
---|
| 358 | if(g_NormalEnable)
|
---|
| 359 | Normal = NormalCalc(tex2D(g_NormalSampler, normalUV).xyz, g_BumpScale);
|
---|
| 360 |
|
---|
| 361 | if(g_SpecularEnable)
|
---|
| 362 | SpecLevel = tex2D(g_SpecularSampler, psIn.UV3).xyz;
|
---|
| 363 |
|
---|
| 364 |
|
---|
| 365 | newCol.rgb = TopCol * Alpha;
|
---|
| 366 | newCol.rgb += BottomCol * (1.0f - Alpha);
|
---|
| 367 | if(g_AddVertexColor)
|
---|
| 368 | newCol.rgb *= psIn.Colour.rgb;
|
---|
| 369 |
|
---|
| 370 | psOut.Colour.rgb = (Ambient + (g_LightCol * saturate(dot(Normal, LightDir)))) * newCol.rgb;
|
---|
| 371 |
|
---|
| 372 | if(g_ReflectionEnable)
|
---|
| 373 | {
|
---|
| 374 | float3 CUV = normalize( reflect( ViewDir, Normal));
|
---|
| 375 | float4 env = texCUBE(g_ReflectionSampler, CUV);
|
---|
| 376 | psOut.Colour.rgb += env.rgb;
|
---|
| 377 | }
|
---|
| 378 |
|
---|
| 379 |
|
---|
| 380 | float3 H = normalize(LightDir + ViewDir);
|
---|
| 381 | float Specular = pow(saturate(dot(Normal, H)), n);
|
---|
| 382 | psOut.Colour.rgb += (k_s.rgb * Specular) * SpecLevel.rgb;
|
---|
| 383 |
|
---|
| 384 | psOut.Colour.a = 1.0f;
|
---|
| 385 | return psOut;
|
---|
| 386 | }
|
---|
| 387 |
|
---|
| 388 |
|
---|
| 389 | technique Default
|
---|
| 390 | {
|
---|
| 391 | pass P0
|
---|
| 392 | {
|
---|
| 393 | AlphaBlendEnable = TRUE;
|
---|
| 394 | DestBlend = InvSrcAlpha;
|
---|
| 395 | SrcBlend = SrcAlpha;
|
---|
| 396 | VertexShader = compile vs_1_1 VS();
|
---|
| 397 | PixelShader = compile ps_2_0 PS();
|
---|
| 398 | }
|
---|
| 399 | }
|
---|