Advertisement
ChaplainTIG

Julius Orig jiWindowBox

Mar 26th, 2021
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.29 KB | None | 0 0
  1. #include <stdosl.h>
  2.  
  3. shader jiWindowBox_Arnold(
  4. int zUpAxis = 0 [[ string widget = "boolean" ]],
  5. string filename = "" [[ string widget = "filename" ]],
  6. int textureFlip = 0 [[ string widget = "boolean" ]],
  7. int textureFlop = 0 [[ string widget = "boolean" ]],
  8. float roomDepth = 1 [[ float min = 0.1, float max = 100 ]],
  9. float widthOverscan = 0 [[ float min = 0.0, float max = 0.9 ]],
  10. float heightOverscan = 0 [[ float min = 0.0, float max = 0.9 ]],
  11. int enableMidground = 0 [[ string widget = "boolean" ]],
  12. float midgroundDepth = 0.5 [[ float min = 0.05, float max = 99 ]],
  13. float midgroundOffsetX = 0,
  14. float midgroundOffsetY = 0,
  15. int enableCurtains = 0 [[ string widget = "boolean" ]],
  16. output color outRGB = 0.0,
  17. )
  18. {
  19. //user controls remapping
  20. float roomDepthMult = clamp(roomDepth,0.1,100);
  21. float heightOverscanMult = 1 - clamp(heightOverscan,0,0.9);
  22. float widthOverscanMult = 1 - clamp(widthOverscan,0,0.9);
  23. float midgroundDepthMult = clamp(midgroundDepth,0.05,roomDepthMult-0.01);
  24. float midgroundOffY = midgroundOffsetY * (textureFlip*2-1) * 0.1;
  25. float midgroundOffX = midgroundOffsetX * (textureFlop*2-1) * 0.1;
  26.  
  27.  
  28. //global variables & remapping
  29. vector objI = transform("object", -I);
  30. if (zUpAxis > 0){
  31. objI = vector(-objI[0],-objI[1],-objI[2]) * color(widthOverscanMult, heightOverscanMult, 1); //reorder to match UV for Y up axis
  32. } else {
  33. objI = vector(-objI[0],objI[2],-objI[1]) * color(widthOverscanMult, heightOverscanMult, 1); //reorder to match UV for Z up axis
  34. }
  35. color objPOrig = (color(u,v,0.5) * 2 - 1) * 0.5 + 0.5; //for curtains
  36. color objP = (color(u,v,0.5) * 2 - 1) * color(widthOverscanMult, heightOverscanMult, 1) * 0.5 + 0.5; //UV seems to be the better approach
  37.  
  38.  
  39. //bases for width/height/depth
  40. vector sections = step(0, objI);
  41. color baseDepth = (objP-sections)/(-objI * roomDepthMult);
  42. color mgDepth = (objP-sections)/(-objI * midgroundDepthMult);
  43. color baseBack = (objP-sections)/(-objI);
  44. color baseWidth = baseDepth * roomDepthMult;
  45.  
  46.  
  47.  
  48. //depth and width ramps
  49. color baseDepthX = (baseDepth[1]*objI+objP + 1);
  50. color baseDepthY = (baseDepth[0]*objI+objP + 1);
  51. color baseWidthX = (baseWidth[1]*objI+objP + 1);
  52. color baseWidthY = (baseWidth[0]*objI+objP + 1);
  53.  
  54. float horizU = baseDepthY[2] - 0.5;
  55. float vertU = baseWidthX[0] - 1;
  56. float horizV = baseWidthY[1] - 1;
  57. float vertV = baseDepthX[2] - 0.5;
  58.  
  59.  
  60. //convert ramps to UV/ST... WIP - not very efficient
  61. float sideWallsMask = step(0,horizU) * step(0,1-max(horizV, 1-horizV));
  62. color sideWallsUV = color(horizU, horizV, 0) / 3;
  63. color rWallUV = (sideWallsUV + color(2.0/3.0, 1.0/3.0, 0)) * sideWallsMask * sections[0];
  64. color lWallUV = (sideWallsUV + color(0.0, 1.0/3.0, 0)) * sideWallsMask * (1-sections[0]);
  65. lWallUV[0] = (1.0/3.0 - lWallUV[0]) * sideWallsMask * (1-sections[0]);
  66.  
  67. float FloorCeilMask = step(0,vertV) * step(0,1-max(vertU, 1-vertU));
  68. color FloorCeilUV = color(vertU, vertV, 0) / 3;
  69. color ceilUV = (FloorCeilUV + color(1.0/3.0, 2.0/3.0, 0)) * FloorCeilMask * sections[1];
  70. color floorUV = (FloorCeilUV + color(1.0/3.0, 0, 0)) * FloorCeilMask * (1-sections[1]);
  71. floorUV[1] = (1.0/3.0 - floorUV[1]) * FloorCeilMask * (1-sections[1]);
  72.  
  73. color backWallUV = ((baseBack[2]*objI + (objP/2)/(roomDepthMult)) * (roomDepthMult*2) / 3 + color(1.0/3.0, 1.0/3.0, 0) ) * (1 - max(step(0,horizU), step(0,vertV)));
  74.  
  75.  
  76. color midgroundUV = (1.0/3.0 - (baseBack[2]*objI + (objP)/(midgroundDepthMult*2)) * (midgroundDepthMult*2) / 3);
  77. float midgroundMask = step( 0, midgroundUV[1] * 3 * (1-midgroundUV[1]*3) ) * step( 0, midgroundUV[0] * (1.0/3.0-midgroundUV[0]) );
  78. midgroundUV = (color(midgroundOffX, midgroundOffY, 0) + midgroundUV) * midgroundMask;
  79. midgroundUV[1] = 1-midgroundUV[1];
  80.  
  81. color curtainsUV = objPOrig * color(1.0/3.0, 1.0/3.0, 1);
  82. curtainsUV[0] = 1.0/3.0 - curtainsUV[0];
  83.  
  84.  
  85.  
  86. color finalUV = ceilUV + floorUV + rWallUV + lWallUV + backWallUV;
  87.  
  88.  
  89.  
  90.  
  91. //flipping ctrl
  92. if (textureFlop > 0){
  93. midgroundUV[0] = 1.0/3.0 - midgroundUV[0];
  94. curtainsUV[0] = 1.0/3.0 - curtainsUV[0];
  95. }else
  96. finalUV[0] = 1-finalUV[0];
  97. if (textureFlip > 0){
  98. finalUV[1] = 1-finalUV[1];
  99. midgroundUV[1] = 1 - midgroundUV[1] + 2.0/3.0;
  100. curtainsUV[1] = 1.0/3.0 - curtainsUV[1];
  101. }
  102.  
  103.  
  104. color roomRGB = texture(filename, finalUV[0], finalUV[1]);
  105.  
  106. color finalRGB;
  107.  
  108.  
  109.  
  110.  
  111. //midground switch
  112. if (enableMidground > 0){
  113. float midgroundA;
  114. color midgroundRGB = texture(filename, midgroundUV[0], midgroundUV[1], "alpha", midgroundA);
  115. finalRGB = mix(roomRGB,midgroundRGB,midgroundA);
  116. }
  117. else{
  118. finalRGB = roomRGB;
  119. }
  120.  
  121.  
  122.  
  123.  
  124. //curtains switch
  125. if (enableCurtains > 0){
  126. float curtainsA;
  127. color curtainsRGB = texture(filename, curtainsUV[0], curtainsUV[1], "alpha", curtainsA);
  128. finalRGB = mix(finalRGB,curtainsRGB,curtainsA);
  129. }
  130.  
  131.  
  132.  
  133.  
  134. outRGB = finalRGB;
  135.  
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement