wavesV.hlsl 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 "hlslStructs.hlsl"
  25. //-----------------------------------------------------------------------------
  26. // Constants
  27. //-----------------------------------------------------------------------------
  28. struct Conn
  29. {
  30. float4 HPOS : POSITION;
  31. float2 TEX0 : TEXCOORD0;
  32. float4 tangentToCube0 : TEXCOORD1;
  33. float4 tangentToCube1 : TEXCOORD2;
  34. float4 tangentToCube2 : TEXCOORD3;
  35. float4 outLightVec : TEXCOORD4;
  36. float3 pos : TEXCOORD5;
  37. float3 outEyePos : TEXCOORD6;
  38. };
  39. uniform float4x4 modelview : register(VC_WORLD_PROJ);
  40. uniform float3x3 cubeTrans : register(VC_CUBE_TRANS);
  41. uniform float3 cubeEyePos : register(VC_CUBE_EYE_POS);
  42. uniform float3 inLightVec : register(VC_LIGHT_DIR1);
  43. uniform float3 eyePos : register(VC_EYE_POS);
  44. //-----------------------------------------------------------------------------
  45. // Main
  46. //-----------------------------------------------------------------------------
  47. Conn main( VertexIn_PNTTTB In)
  48. {
  49. Conn Out;
  50. Out.HPOS = mul(modelview, float4(In.pos,1.0));
  51. Out.TEX0 = In.uv0;
  52. float3x3 objToTangentSpace;
  53. objToTangentSpace[0] = In.T;
  54. objToTangentSpace[1] = In.B;
  55. objToTangentSpace[2] = In.normal;
  56. Out.tangentToCube0.xyz = mul( objToTangentSpace, cubeTrans[0].xyz );
  57. Out.tangentToCube1.xyz = mul( objToTangentSpace, cubeTrans[1].xyz );
  58. Out.tangentToCube2.xyz = mul( objToTangentSpace, cubeTrans[2].xyz );
  59. float3 pos = mul( cubeTrans, In.pos ).xyz;
  60. float3 eye = cubeEyePos - pos;
  61. normalize( eye );
  62. Out.tangentToCube0.w = eye.x;
  63. Out.tangentToCube1.w = eye.y;
  64. Out.tangentToCube2.w = eye.z;
  65. Out.outLightVec.xyz = -inLightVec;
  66. Out.outLightVec.xyz = mul(objToTangentSpace, Out.outLightVec);
  67. Out.pos = mul(objToTangentSpace, In.pos.xyz / 100.0);
  68. Out.outEyePos.xyz = mul(objToTangentSpace, eyePos.xyz / 100.0);
  69. Out.outLightVec.w = step( 0.0, dot( -inLightVec, In.normal ) );
  70. return Out;
  71. }