assign-color-varying.glsl.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. export const assign_color_varying = `
  2. #if defined(dRenderVariant_color)
  3. #if defined(dColorType_attribute)
  4. vColor.rgb = aColor;
  5. #elif defined(dColorType_instance)
  6. vColor.rgb = readFromTexture(tColor, aInstance, uColorTexDim).rgb;
  7. #elif defined(dColorType_group)
  8. vColor.rgb = readFromTexture(tColor, group, uColorTexDim).rgb;
  9. #elif defined(dColorType_groupInstance)
  10. vColor.rgb = readFromTexture(tColor, aInstance * float(uGroupCount) + group, uColorTexDim).rgb;
  11. #elif defined(dColorType_vertex)
  12. vColor.rgb = readFromTexture(tColor, VertexID, uColorTexDim).rgb;
  13. #elif defined(dColorType_vertexInstance)
  14. vColor.rgb = readFromTexture(tColor, int(aInstance) * uVertexCount + VertexID, uColorTexDim).rgb;
  15. #elif defined(dColorType_volume)
  16. vec3 cgridPos = (uColorGridTransform.w * (position - uColorGridTransform.xyz)) / uColorGridDim;
  17. vColor.rgb = texture3dFrom2dLinear(tColorGrid, cgridPos, uColorGridDim, uColorTexDim).rgb;
  18. #elif defined(dColorType_volumeInstance)
  19. vec3 cgridPos = (uColorGridTransform.w * (vModelPosition - uColorGridTransform.xyz)) / uColorGridDim;
  20. vColor.rgb = texture3dFrom2dLinear(tColorGrid, cgridPos, uColorGridDim, uColorTexDim).rgb;
  21. #endif
  22. #ifdef dUsePalette
  23. vPaletteV = ((vColor.r * 256.0 * 256.0 * 255.0 + vColor.g * 256.0 * 255.0 + vColor.b * 255.0) - 1.0) / 16777215.0;
  24. #endif
  25. #ifdef dOverpaint
  26. #if defined(dOverpaintType_instance)
  27. vOverpaint = readFromTexture(tOverpaint, aInstance, uOverpaintTexDim);
  28. #elif defined(dOverpaintType_groupInstance)
  29. vOverpaint = readFromTexture(tOverpaint, aInstance * float(uGroupCount) + group, uOverpaintTexDim);
  30. #elif defined(dOverpaintType_vertexInstance)
  31. vOverpaint = readFromTexture(tOverpaint, int(aInstance) * uVertexCount + VertexID, uOverpaintTexDim);
  32. #elif defined(dOverpaintType_volumeInstance)
  33. vec3 ogridPos = (uOverpaintGridTransform.w * (vModelPosition - uOverpaintGridTransform.xyz)) / uOverpaintGridDim;
  34. vOverpaint = texture3dFrom2dLinear(tOverpaintGrid, ogridPos, uOverpaintGridDim, uOverpaintTexDim);
  35. #endif
  36. // pre-mix to avoid darkening due to empty overpaint
  37. #ifdef dColorType_uniform
  38. vOverpaint.rgb = mix(uColor.rgb, vOverpaint.rgb, vOverpaint.a);
  39. #else
  40. vOverpaint.rgb = mix(vColor.rgb, vOverpaint.rgb, vOverpaint.a);
  41. #endif
  42. vOverpaint *= uOverpaintStrength;
  43. #endif
  44. #ifdef dSubstance
  45. #if defined(dSubstanceType_instance)
  46. vSubstance = readFromTexture(tSubstance, aInstance, uSubstanceTexDim);
  47. #elif defined(dSubstanceType_groupInstance)
  48. vSubstance = readFromTexture(tSubstance, aInstance * float(uGroupCount) + group, uSubstanceTexDim);
  49. #elif defined(dSubstanceType_vertexInstance)
  50. vSubstance = readFromTexture(tSubstance, int(aInstance) * uVertexCount + VertexID, uSubstanceTexDim);
  51. #elif defined(dSubstanceType_volumeInstance)
  52. vec3 sgridPos = (uSubstanceGridTransform.w * (vModelPosition - uSubstanceGridTransform.xyz)) / uSubstanceGridDim;
  53. vSubstance = texture3dFrom2dLinear(tSubstanceGrid, sgridPos, uSubstanceGridDim, uSubstanceTexDim);
  54. #endif
  55. // pre-mix to avoid artifacts due to empty substance
  56. vSubstance.rgb = mix(vec3(uMetalness, uRoughness, uBumpiness), vSubstance.rgb, vSubstance.a);
  57. vSubstance *= uSubstanceStrength;
  58. #endif
  59. #elif defined(dRenderVariant_pick)
  60. #ifdef requiredDrawBuffers
  61. vObject = vec4(packIntToRGB(float(uObjectId)), 1.0);
  62. vInstance = vec4(packIntToRGB(aInstance), 1.0);
  63. vGroup = vec4(packIntToRGB(group), 1.0);
  64. #else
  65. if (uPickType == 1) {
  66. vColor = vec4(packIntToRGB(float(uObjectId)), 1.0);
  67. } else if (uPickType == 2) {
  68. vColor = vec4(packIntToRGB(aInstance), 1.0);
  69. } else {
  70. vColor = vec4(packIntToRGB(group), 1.0);
  71. }
  72. #endif
  73. #endif
  74. #ifdef dTransparency
  75. #if defined(dTransparencyType_instance)
  76. vTransparency = readFromTexture(tTransparency, aInstance, uTransparencyTexDim).a;
  77. #elif defined(dTransparencyType_groupInstance)
  78. vTransparency = readFromTexture(tTransparency, aInstance * float(uGroupCount) + group, uTransparencyTexDim).a;
  79. #elif defined(dTransparencyType_vertexInstance)
  80. vTransparency = readFromTexture(tTransparency, int(aInstance) * uVertexCount + VertexID, uTransparencyTexDim).a;
  81. #elif defined(dTransparencyType_volumeInstance)
  82. vec3 tgridPos = (uTransparencyGridTransform.w * (vModelPosition - uTransparencyGridTransform.xyz)) / uTransparencyGridDim;
  83. vTransparency = texture3dFrom2dLinear(tTransparencyGrid, tgridPos, uTransparencyGridDim, uTransparencyTexDim).a;
  84. #endif
  85. vTransparency *= uTransparencyStrength;
  86. #endif
  87. `;