PickingAlphaCull.bslinc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. Parameters =
  2. {
  3. mat4x4 matWorldViewProj;
  4. float alphaCutoff;
  5. float4 colorIndex;
  6. Sampler2D mainTexSamp : alias("mainTexture");
  7. Texture2D mainTexture;
  8. };
  9. Technique : base("PickingAlphaCull") =
  10. {
  11. Language = "HLSL11";
  12. Pass =
  13. {
  14. Scissor = true;
  15. Vertex =
  16. {
  17. float4x4 matWorldViewProj;
  18. void main(
  19. in float3 inPos : POSITION,
  20. in float3 inNorm : NORMAL,
  21. in float2 uv : TEXCOORD0,
  22. out float4 oPosition : SV_Position,
  23. out float4 oNorm : NORMAL,
  24. out float2 oUv : TEXCOORD0)
  25. {
  26. oPosition = mul(matWorldViewProj, float4(inPos.xyz, 1));
  27. oNorm = float4(inNorm, 0);
  28. oUv = uv;
  29. }
  30. };
  31. Fragment =
  32. {
  33. SamplerState mainTexSamp : register(s0);
  34. Texture2D mainTexture : register(t0);
  35. float4 colorIndex;
  36. float alphaCutoff;
  37. float4 main(
  38. in float4 inPos : SV_Position,
  39. in float4 inNorm : NORMAL,
  40. in float2 uv : TEXCOORD0,
  41. out float4 oNorm : SV_Target1) : SV_Target0
  42. {
  43. float4 color = mainTexture.Sample(mainTexSamp, uv);
  44. oNorm = (inNorm + float4(1,1,1,0)) / 2;
  45. if(color.a < alphaCutoff)
  46. discard;
  47. return colorIndex;
  48. }
  49. };
  50. };
  51. };
  52. Technique : base("PickingAlphaCull") =
  53. {
  54. Language = "HLSL9";
  55. Pass =
  56. {
  57. Scissor = true;
  58. Vertex =
  59. {
  60. float4x4 matWorldViewProj;
  61. void main(
  62. in float3 inPos : POSITION,
  63. in float2 uv : TEXCOORD0,
  64. out float4 oPosition : POSITION,
  65. out float2 oUv : TEXCOORD0)
  66. {
  67. oPosition = mul(matWorldViewProj, float4(inPos.xyz, 1));
  68. oUv = uv;
  69. }
  70. };
  71. Fragment =
  72. {
  73. sampler2D mainTexture;
  74. float4 colorIndex;
  75. float alphaCutoff;
  76. float4 main(
  77. in float4 inPos : POSITION,
  78. in float2 uv : TEXCOORD0) : COLOR0
  79. {
  80. float4 color = tex2D(mainTexture, uv);
  81. if(color.a < alphaCutoff)
  82. discard;
  83. return colorIndex;
  84. }
  85. };
  86. };
  87. };
  88. Technique : base("PickingAlphaCull") =
  89. {
  90. Language = "GLSL";
  91. Pass =
  92. {
  93. Scissor = true;
  94. Vertex =
  95. {
  96. uniform mat4 matWorldViewProj;
  97. in vec3 bs_position;
  98. in vec2 bs_texcoord0;
  99. in vec3 bs_normal;
  100. out vec4 normal
  101. out vec2 texcoord0;
  102. out gl_PerVertex
  103. {
  104. vec4 gl_Position;
  105. };
  106. void main()
  107. {
  108. gl_Position = matWorldViewProj * vec4(bs_position.xyz, 1);
  109. texcoord0 = bs_texcoord0;
  110. normal = vec4(bs_normal, 0);
  111. }
  112. };
  113. Fragment =
  114. {
  115. uniform sampler2D mainTexture;
  116. uniform vec4 colorIndex;
  117. uniform float alphaCutoff;
  118. in vec4 normal;
  119. in vec2 texcoord0;
  120. out vec4 normalsColor;
  121. out vec4 fragColor;
  122. void main()
  123. {
  124. vec4 color = texture2D(mainTexture, texcoord0);
  125. if(color.a < alphaCutoff)
  126. discard;
  127. normalsColor = (normal + vec4(1,1,1,0)) / 2;
  128. fragColor = colorIndex;
  129. }
  130. };
  131. };
  132. };