heathaze.vertex 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #include "global.inc"
  21. // User Renderparms start at 128 as per renderprogs.h
  22. uniform float4 rpUser0 : register(c128); // rpScroll
  23. uniform float4 rpUser1 : register(c129); // rpDeformMagnitude
  24. uniform matrices_ubo { float4 matrices[408]; };
  25. struct VS_IN {
  26. float4 position : POSITION;
  27. float2 texcoord : TEXCOORD0;
  28. float4 normal : NORMAL;
  29. float4 tangent : TANGENT;
  30. float4 color : COLOR0;
  31. float4 color2 : COLOR1;
  32. };
  33. struct VS_OUT {
  34. float4 position : POSITION;
  35. float4 texcoord0 : TEXCOORD0;
  36. float4 texcoord1 : TEXCOORD1;
  37. };
  38. void main( VS_IN vertex, out VS_OUT result ) {
  39. #include "skinning.inc"
  40. //texture 0 takes the texture coordinates and adds a scroll
  41. const float4 textureScroll = rpUser0;
  42. result.texcoord0 = float4( vertex.texcoord.xy, 0, 0 ) + textureScroll;
  43. //texture 1 takes the deform magnitude and scales it by the projection distance
  44. float4 vec = float4( 0, 1, 0, 1 );
  45. vec.z = dot4( modelPosition, rpModelViewMatrixZ ); // this is the modelview matrix
  46. // magicProjectionAdjust is a magic scalar that scales the projection since we changed from
  47. // using the X axis to the Y axis to calculate x. It is an approximation to closely match
  48. // what the original game did
  49. const float magicProjectionAdjust = 0.43f;
  50. float x = dot4( vec, rpProjectionMatrixY ) * magicProjectionAdjust;
  51. float w = dot4( vec, rpProjectionMatrixW );
  52. //don't let the recip get near zero for polygons that cross the view plane
  53. w = max( w, 1.0 );
  54. x /= w;
  55. //x = x * ( 1.0f / w );
  56. // clamp the distance so the the deformations don't get too wacky near the view
  57. x = min( x, 0.02 );
  58. const float4 deformMagnitude = rpUser1;
  59. result.texcoord1 = x * deformMagnitude;
  60. }