wavesP.hlsl 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #define IN_HLSL
  23. #include "shdrConsts.h"
  24. #include "shaderModel.hlsl"
  25. //-----------------------------------------------------------------------------
  26. // Data
  27. //-----------------------------------------------------------------------------
  28. struct v2f
  29. {
  30. float4 HPOS : TORQUE_POSITION;
  31. float2 TEX0 : TEXCOORD0;
  32. float4 tangentToCube0 : TEXCOORD1;
  33. float4 tangentToCube1 : TEXCOORD2;
  34. float4 tangentToCube2 : TEXCOORD3;
  35. float4 lightVec : TEXCOORD4;
  36. float3 pixPos : TEXCOORD5;
  37. float3 eyePos : TEXCOORD6;
  38. };
  39. struct Fragout
  40. {
  41. float4 col : TORQUE_TARGET0;
  42. };
  43. // Uniforms
  44. TORQUE_UNIFORM_SAMPLER2D(diffMap,0);
  45. //TORQUE_UNIFORM_SAMPLERCUBE(cubeMap, 1); not used?
  46. TORQUE_UNIFORM_SAMPLER2D(bumpMap,2);
  47. uniform float4 specularColor : register(PC_MAT_SPECCOLOR);
  48. uniform float4 ambient : register(PC_AMBIENT_COLOR);
  49. uniform float specularPower : register(PC_MAT_SPECPOWER);
  50. uniform float accumTime : register(PC_ACCUM_TIME);
  51. //-----------------------------------------------------------------------------
  52. // Main
  53. //-----------------------------------------------------------------------------
  54. Fragout main(v2f IN)
  55. {
  56. Fragout OUT;
  57. float2 texOffset;
  58. float sinOffset1 = sin( accumTime * 1.5 + IN.TEX0.y * 6.28319 * 3.0 ) * 0.03;
  59. float sinOffset2 = sin( accumTime * 3.0 + IN.TEX0.y * 6.28319 ) * 0.04;
  60. texOffset.x = IN.TEX0.x + sinOffset1 + sinOffset2;
  61. texOffset.y = IN.TEX0.y + cos( accumTime * 3.0 + IN.TEX0.x * 6.28319 * 2.0 ) * 0.05;
  62. float4 bumpNorm = TORQUE_TEX2D( bumpMap, texOffset ) * 2.0 - 1.0;
  63. float4 diffuse = TORQUE_TEX2D( diffMap, texOffset );
  64. OUT.col = diffuse * (saturate( dot( IN.lightVec, bumpNorm.xyz ) ) + ambient);
  65. float3 eyeVec = normalize(IN.eyePos - IN.pixPos);
  66. float3 halfAng = normalize(eyeVec + IN.lightVec.xyz);
  67. float specular = saturate( dot(bumpNorm, halfAng) ) * IN.lightVec.w;
  68. specular = pow(abs(specular), specularPower);
  69. OUT.col += specularColor * specular;
  70. return OUT;
  71. }