Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
3.4 KiB

  1. #include "common_vs_fxc.h"
  2. //---------------------------------------------------------------------------------//
  3. // Parallax occlusion mapping algorithm implementation. Vertex shader.
  4. //---------------------------------------------------------------------------------//
  5. #define matWorldViewProjection cModelViewProj
  6. //float4x4 matViewInverse;
  7. //float4x4 matView;
  8. //float fBaseTextureRepeat;
  9. //float4 vLightPosition;
  10. struct VS_INPUT
  11. {
  12. float4 positionWS : POSITION;
  13. float3 vNormalWS : NORMAL;
  14. float2 texCoord : TEXCOORD0;
  15. float3 vBinormalWS : BINORMAL;
  16. float3 vTangentWS : TANGENT;
  17. };
  18. struct VS_OUTPUT
  19. {
  20. float4 position : POSITION; // proj-space position
  21. float2 texCoord : TEXCOORD0;
  22. // float3 vLightTS : TEXCOORD1; // light vector in tangent space, denormalized
  23. float3 vViewTS : TEXCOORD2; // view vector in tangent space, denormalized
  24. float2 vParallaxOffsetTS : TEXCOORD3; // Parallax offset vector in tangent space
  25. float3 vNormalWS : TEXCOORD4; // Normal vector in world space
  26. float3 vViewWS : TEXCOORD5; // View vector in world space
  27. float4 vDebug : TEXCOORD6;
  28. };
  29. VS_OUTPUT main( VS_INPUT i )
  30. {
  31. VS_OUTPUT Out = (VS_OUTPUT) 0;
  32. // Transform and output input position
  33. Out.position = mul( float4( i.positionWS.xyz, 1 ), cModelViewProj );
  34. //Out.position = mul( matWorldViewProjection, i.positionWS );
  35. // Propagate texture coordinate through:
  36. Out.texCoord = i.texCoord;
  37. // Uncomment this to repeat the texture
  38. // Out.texCoord *= fBaseTextureRepeat;
  39. // Propagate the world vertex normal through:
  40. Out.vNormalWS = i.vNormalWS;
  41. // Compute and output the world view vector:
  42. float3 vViewWS = cEyePos - i.positionWS;
  43. Out.vViewWS = vViewWS;
  44. // Compute denormalized light vector in world space:
  45. // float3 vLightWS = vLightPosition - i.positionWS;
  46. // Normalize the light and view vectors and transform it to the tangent space:
  47. float3x3 mWorldToTangent = float3x3( i.vTangentWS, i.vBinormalWS, i.vNormalWS );
  48. // float3x3 mWorldToTangent = float3x3( i.vBinormalWS, i.vTangentWS, i.vNormalWS );
  49. // Propagate the view and the light vectors (in tangent space):
  50. // Out.vLightTS = mul( mWorldToTangent, vLightWS );
  51. Out.vViewTS = mul( mWorldToTangent, vViewWS );
  52. float fHeightMapRange = 0.02f; // FIXME: should be a vmt param
  53. // Compute the ray direction for intersecting the height field profile with
  54. // current view ray. See the above paper for derivation of this computation.
  55. // Compute initial parallax displacement direction:
  56. float2 vParallaxDirection = normalize( Out.vViewTS.xy );
  57. // The length of this vector determines the furthest amount of displacement:
  58. float fLength = length( Out.vViewTS );
  59. float fParallaxLength = sqrt( fLength * fLength - Out.vViewTS.z * Out.vViewTS.z ) / Out.vViewTS.z;
  60. // Compute the actual reverse parallax displacement vector:
  61. Out.vParallaxOffsetTS = vParallaxDirection * fParallaxLength;
  62. // Need to scale the amount of displacement to account for different height ranges
  63. // in height maps. This is controlled by an artist-editable parameter:
  64. Out.vParallaxOffsetTS *= fHeightMapRange;
  65. Out.vDebug = float4( 1.0f, 0.0f, 0.0f, 1.0f );
  66. Out.vDebug.xy = vParallaxDirection;
  67. // Out.vDebug.xyz = ( float3 )fHeightMapRange;
  68. Out.vDebug.xyz = fParallaxLength * .1;
  69. Out.vDebug.xyz = fHeightMapRange * 200;
  70. return Out;
  71. } // End of VS_OUTPUT vs_main(..)