Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

pixel

By: a guest on May 14th, 2013  |  syntax: None  |  size: 4.25 KB  |  hits: 37  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include "shadergen:/autogenConditioners.h"
  2. #include "shaders/common/torque.hlsl"
  3. uniform sampler2D ColorSampler: register(s0);
  4. uniform sampler2D Mask1Sampler: register(s1);
  5. uniform sampler2D Mask2Sampler: register(s2);
  6. uniform sampler2D NormalSampler: register(s3);
  7. uniform sampler1D GradientMapSampler: register(s4);
  8.  
  9.  
  10. /* data passed from vertex shader to pixel shader */
  11. struct PS_INPUT {
  12.     float4 HPosition    : POSITION;
  13.     float2 UV           : TEXCOORD0;
  14.     float3 LightVec     : TEXCOORD1;
  15.     float3 WorldNormal  : TEXCOORD2;
  16.     float3 WorldTangent : TEXCOORD3;
  17.     float3 WorldBinormal : TEXCOORD4;
  18.     float3 WorldView    : TEXCOORD5;
  19. };
  20.  
  21. struct PS_OUTPUT
  22. {
  23. float4 result : COLOR0;
  24. };
  25.  
  26.  
  27. PS_OUTPUT main(PS_INPUT IN){
  28.         PS_OUTPUT OUT = (PS_OUTPUT)0;
  29.     float3 Ln = normalize(IN.LightVec); //light direction
  30.     float3 Nn = normalize(IN.WorldNormal);
  31.         float3 Tn = normalize(IN.WorldTangent);
  32.        
  33.         //half lambert
  34.     float ldn = pow(((dot(Ln,Nn))/2)+0.5f,2);
  35.         ldn = max(ldn,0.0);
  36.        
  37.         ////////////////// Diffuse////////////////////
  38.        
  39.     float3 diffuseColor = tex2D(ColorSampler,IN.UV).rgb;
  40.        
  41.         ////////////////// Normal ///////////////////////
  42.  
  43.     float3 Bn = normalize(IN.WorldBinormal);
  44.     float3 bump = 10 * (tex2D(NormalSampler,IN.UV).rgb - float3(0.5,0.5,0.5));
  45.     Nn = Nn + bump.x*Tn + bump.y*Bn;
  46.     Nn = normalize(Nn);
  47.  
  48.        
  49.         //---------------------------------------------------------
  50.        
  51.         ////////////////// Mask 1 //////////////////////
  52.         ////////////////// G - Specular Exponent (sharpness of light) ////////////////////////// NEED TO FIX THIS SO IT USES THE MAP TO DECIDE THE SHARPNESS
  53.        
  54.         float3 specularExponent = tex2D(Mask1Sampler,IN.UV).rgb;
  55.         specularExponent.rb = specularExponent.g;  
  56.        
  57.         ////////////////// R - Specular intensity ///////////////////////
  58.         float3 reflectionVector = 2*dot(Nn, Ln)*Nn - Ln;
  59.         float3 specularIntensity = tex2D(Mask1Sampler,IN.UV).rgb;
  60.         specularIntensity.gb = specularIntensity.r;  
  61.        
  62.         specularIntensity = pow(saturate (dot(reflectionVector, IN.WorldView)),1/(specularExponent*specularIntensity));
  63.  
  64.        
  65.         ////////////////// B - specular colour mask(where the mask is, tells if the specular is tinted) ////////////////////
  66.         float3 specularColourMask = tex2D(Mask1Sampler,IN.UV).rgb;
  67.         specularColourMask.rg = specularColourMask.b;
  68.        
  69.         specularIntensity *= specularColourMask * diffuseColor;
  70.        
  71.        
  72.         //--------------------------------------------------------------------
  73.        
  74.                 ////////////////// Mask 2 //////////////////////
  75.         ////////////////// R - Diffuse/fresnel mask colour warp (like gradient map layer in PS)  //////////////////////////
  76.         float3 fresnelVector = 1-dot(Nn, IN.WorldView);
  77.         float3 fresnelMask = tex2D(Mask2Sampler,IN.UV).rgb;
  78.         fresnelMask.gb = fresnelMask.r;  
  79.         float3 fresnelColour;
  80.        
  81.         float3 InColor = tex2D(ColorSampler, IN.UV).xyz;
  82.        
  83.         fresnelColour.r = tex1D(GradientMapSampler, InColor.r).r;
  84.         fresnelColour.g = tex1D(GradientMapSampler, InColor.g).g;
  85.         fresnelColour.b = tex1D(GradientMapSampler, InColor.b).b;
  86.        
  87.         fresnelColour *= pow(saturate(fresnelVector),2)*fresnelMask;
  88.  
  89.         ////////////////// G - Rim light intensity ///////////////////////
  90.         float3 rimLightVector = 1-dot(Nn, IN.WorldView);
  91.         float3 rimLightIntensity = tex2D(Mask2Sampler,IN.UV).rgb;
  92.         rimLightIntensity.rb = rimLightIntensity.g;  
  93.        
  94.         rimLightIntensity *= pow(saturate(rimLightVector),8)* float3(0.8,0.8,0.8)/*RimColour*/;
  95.        
  96.        
  97.        
  98.         ////////////////// B - self-illumination mask(illuminated areas will be colour of the diffuse) ////////////////////
  99.         float3 selfIllumination = tex2D(Mask2Sampler,IN.UV).rgb;
  100.         selfIllumination.rg = selfIllumination.b;  
  101.        
  102.        
  103.        
  104.         ///////////////// A - diffuse remapping ///////////////////////////////////////////////
  105.         //add variation to the texture by simply inputting a 1x256 pixel gradient
  106.        
  107.         /*
  108.         float3 InColor = tex2D(ColorSampler, IN.UV).xyz;
  109.        
  110.         diffuseColor.r = tex1D(GradientMapSampler, InColor.r).r;
  111.         diffuseColor.g = tex1D(GradientMapSampler, InColor.g).g;
  112.         diffuseColor.b = tex1D(GradientMapSampler, InColor.b).b;
  113.        
  114.  
  115.         */
  116.        
  117.        
  118.        
  119.         //--------------------------------------------------------------------
  120.  
  121.        
  122.         //result
  123.     float3 result = (diffuseColor * (ldn * Lamp0Color + AmbiColor)) + fresnelColour + specularIntensity + rimLightIntensity;
  124.        
  125.     // return as float4
  126.     return OUT;
  127. }