shaderModel.hlsl 4.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2015 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. #ifndef _TORQUE_SHADERMODEL_
  23. #define _TORQUE_SHADERMODEL_
  24. // Portability helpers for different shader models
  25. //Shader model 1.0 - 3.0
  26. #if (TORQUE_SM >= 10 && TORQUE_SM <=30)
  27. // Semantics
  28. #define TORQUE_POSITION POSITION
  29. #define TORQUE_DEPTH DEPTH
  30. #define TORQUE_TARGET0 COLOR0
  31. #define TORQUE_TARGET1 COLOR1
  32. #define TORQUE_TARGET2 COLOR2
  33. #define TORQUE_TARGET3 COLOR3
  34. // Sampler uniforms
  35. #define TORQUE_UNIFORM_SAMPLER1D(tex,regist) uniform sampler1D tex : register(S##regist)
  36. #define TORQUE_UNIFORM_SAMPLER2D(tex,regist) uniform sampler2D tex : register(S##regist)
  37. #define TORQUE_UNIFORM_SAMPLER3D(tex,regist) uniform sampler3D tex : register(S##regist)
  38. #define TORQUE_UNIFORM_SAMPLERCUBE(tex,regist) uniform samplerCUBE tex : register(S##regist)
  39. // Sampling functions
  40. #define TORQUE_TEX1D(tex,coords) tex1D(tex,coords)
  41. #define TORQUE_TEX2D(tex,coords) tex2D(tex,coords)
  42. #define TORQUE_TEX2DPROJ(tex,coords) tex2Dproj(tex,coords) //this really is sm 2 or later
  43. #define TORQUE_TEX3D(tex,coords) tex3D(tex,coords)
  44. #define TORQUE_TEXCUBE(tex,coords) texCUBE(tex,coords)
  45. //Shader model 3.0 only
  46. #if TORQUE_SM == 30
  47. #define TORQUE_VPOS VPOS // This is a float2
  48. // The mipmap LOD is specified in coord.w
  49. #define TORQUE_TEX2DLOD(tex,coords) tex2Dlod(tex,coords)
  50. #endif
  51. //helper if you want to pass sampler/texture in a function
  52. //2D
  53. #define TORQUE_SAMPLER2D(tex) sampler2D tex
  54. #define TORQUE_SAMPLER2D_MAKEARG(tex) tex
  55. //Cube
  56. #define TORQUE_SAMPLERCUBE(tex) samplerCUBE tex
  57. #define TORQUE_SAMPLERCUBE_MAKEARG(tex) tex
  58. // Shader model 4.0+
  59. #elif TORQUE_SM >= 40
  60. #define TORQUE_POSITION SV_Position
  61. #define TORQUE_DEPTH SV_Depth
  62. #define TORQUE_VPOS SV_Position //note float4 compared to SM 3 where it is a float2
  63. #define TORQUE_TARGET0 SV_Target0
  64. #define TORQUE_TARGET1 SV_Target1
  65. #define TORQUE_TARGET2 SV_Target2
  66. #define TORQUE_TARGET3 SV_Target3
  67. // Sampler uniforms
  68. //1D is emulated to a 2D for now
  69. #define TORQUE_UNIFORM_SAMPLER1D(tex,regist) uniform Texture2D texture_##tex : register(T##regist); uniform SamplerState tex : register(S##regist)
  70. #define TORQUE_UNIFORM_SAMPLER2D(tex,regist) uniform Texture2D texture_##tex : register(T##regist); uniform SamplerState tex : register(S##regist)
  71. #define TORQUE_UNIFORM_SAMPLER3D(tex,regist) uniform Texture3D texture_##tex : register(T##regist); uniform SamplerState tex : register(S##regist)
  72. #define TORQUE_UNIFORM_SAMPLERCUBE(tex,regist) uniform TextureCube texture_##tex : register(T##regist); uniform SamplerState tex : register(S##regist)
  73. // Sampling functions
  74. #define TORQUE_TEX1D(tex,coords) texture_##tex.Sample(tex,coords)
  75. #define TORQUE_TEX2D(tex,coords) texture_##tex.Sample(tex,coords)
  76. #define TORQUE_TEX2DPROJ(tex,coords) texture_##tex.Sample(tex,coords.xy / coords.w)
  77. #define TORQUE_TEX3D(tex,coords) texture_##tex.Sample(tex,coords)
  78. #define TORQUE_TEXCUBE(tex,coords) texture_##tex.Sample(tex,coords)
  79. // The mipmap LOD is specified in coord.w
  80. #define TORQUE_TEX2DLOD(tex,coords) texture_##tex.SampleLevel(tex,coords.xy,coords.w)
  81. //helper if you want to pass sampler/texture in a function
  82. //2D
  83. #define TORQUE_SAMPLER2D(tex) Texture2D texture_##tex, SamplerState tex
  84. #define TORQUE_SAMPLER2D_MAKEARG(tex) texture_##tex, tex
  85. //Cube
  86. #define TORQUE_SAMPLERCUBE(tex) TextureCube texture_##tex, SamplerState tex
  87. #define TORQUE_SAMPLERCUBE_MAKEARG(tex) texture_##tex, tex
  88. #endif
  89. #endif // _TORQUE_SHADERMODEL_