assign-color-varying.glsl.ts 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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_groupInstance)
  27. vOverpaint = readFromTexture(tOverpaint, aInstance * float(uGroupCount) + group, uOverpaintTexDim);
  28. #elif defined(dOverpaintType_vertexInstance)
  29. vOverpaint = readFromTexture(tOverpaint, int(aInstance) * uVertexCount + VertexID, uOverpaintTexDim);
  30. #elif defined(dOverpaintType_volumeInstance)
  31. vec3 ogridPos = (uOverpaintGridTransform.w * (vModelPosition - uOverpaintGridTransform.xyz)) / uOverpaintGridDim;
  32. vOverpaint = texture3dFrom2dLinear(tOverpaintGrid, ogridPos, uOverpaintGridDim, uOverpaintTexDim);
  33. #endif
  34. // pre-mix to avoid darkening due to empty overpaint
  35. #ifdef dColorType_uniform
  36. vOverpaint.rgb = mix(uColor.rgb, vOverpaint.rgb, vOverpaint.a);
  37. #else
  38. vOverpaint.rgb = mix(vColor.rgb, vOverpaint.rgb, vOverpaint.a);
  39. #endif
  40. #endif
  41. #ifdef dSubstance
  42. #if defined(dSubstanceType_groupInstance)
  43. vSubstance = readFromTexture(tSubstance, aInstance * float(uGroupCount) + group, uSubstanceTexDim);
  44. #elif defined(dSubstanceType_vertexInstance)
  45. vSubstance = readFromTexture(tSubstance, int(aInstance) * uVertexCount + VertexID, uSubstanceTexDim);
  46. #elif defined(dSubstanceType_volumeInstance)
  47. vec3 sgridPos = (uSubstanceGridTransform.w * (vModelPosition - uSubstanceGridTransform.xyz)) / uSubstanceGridDim;
  48. vSubstance = texture3dFrom2dLinear(tSubstanceGrid, sgridPos, uSubstanceGridDim, uSubstanceTexDim);
  49. #endif
  50. // pre-mix to avoid artifacts due to empty substance
  51. vSubstance.rgb = mix(vec3(uMetalness, uRoughness, uBumpiness), vSubstance.rgb, vSubstance.a);
  52. #endif
  53. #elif defined(dRenderVariant_pick)
  54. #ifdef requiredDrawBuffers
  55. vObject = vec4(packIntToRGB(float(uObjectId)), 1.0);
  56. vInstance = vec4(packIntToRGB(aInstance), 1.0);
  57. vGroup = vec4(packIntToRGB(group), 1.0);
  58. #else
  59. if (uPickType == 1) {
  60. vColor = vec4(packIntToRGB(float(uObjectId)), 1.0);
  61. } else if (uPickType == 2) {
  62. vColor = vec4(packIntToRGB(aInstance), 1.0);
  63. } else {
  64. vColor = vec4(packIntToRGB(group), 1.0);
  65. }
  66. #endif
  67. #endif
  68. #ifdef dTransparency
  69. vGroup = group;
  70. #if defined(dTransparencyType_groupInstance)
  71. vTransparency = readFromTexture(tTransparency, aInstance * float(uGroupCount) + group, uTransparencyTexDim).a;
  72. #elif defined(dTransparencyType_vertexInstance)
  73. vTransparency = readFromTexture(tTransparency, int(aInstance) * uVertexCount + VertexID, uTransparencyTexDim).a;
  74. #elif defined(dTransparencyType_volumeInstance)
  75. vec3 tgridPos = (uTransparencyGridTransform.w * (vModelPosition - uTransparencyGridTransform.xyz)) / uTransparencyGridDim;
  76. vTransparency = texture3dFrom2dLinear(tTransparencyGrid, tgridPos, uTransparencyGridDim, uTransparencyTexDim).a;
  77. #endif
  78. #endif
  79. `;