@@ -104,7 +104,7 @@ public static boolean pathTrace(Scene scene, Ray ray, WorkerState state, int add
104104
105105 float pSpecular = currentMat .specular ;
106106
107- double pDiffuse = 1 - Math .sqrt (1 - ray .color .w );
107+ double pDiffuse = scene . fancierTranslucency ? 1 - Math .sqrt (1 - ray .color .w ) : ray . color . w ;
108108
109109 float n1 = prevMat .ior ;
110110 float n2 = currentMat .ior ;
@@ -425,50 +425,57 @@ private static boolean doTransmission(Ray ray, Ray next, Vector4 cumulativeColor
425425 }
426426
427427 private static void translucentRayColor (Scene scene , Ray ray , Ray next , Vector4 cumulativeColor , double opacity ) {
428- // Color-based transmission value
429- double colorTrans = (ray .color .x + ray .color .y + ray .color .z )/3 ;
430- // Total amount of light we want to transmit (overall transparency of texture)
431- double shouldTrans = 1 - opacity ;
432- // Amount of each color to transmit - default to overall transparency if RGB values add to 0 (e.g. regular glass)
433- Vector3 rgbTrans = new Vector3 (shouldTrans , shouldTrans , shouldTrans );
434- if (colorTrans > 0 ) {
435- // Amount to transmit of each color is scaled so the total transmitted amount matches the texture's transparency
436- rgbTrans .set (ray .color .toVec3 ());
437- rgbTrans .scale (shouldTrans / colorTrans );
438- }
439- double transmissivityCap = scene .transmissivityCap ;
440- // Determine the color with the highest transmissivity
441- double maxTrans = Math .max (rgbTrans .x , Math .max (rgbTrans .y , rgbTrans .z ));
442- if (maxTrans > transmissivityCap ) {
443- if (maxTrans == rgbTrans .x ) {
444- // Give excess transmission from red to green and blue
445- double gTransNew = reassignTransmissivity (rgbTrans .x , rgbTrans .y , rgbTrans .z , shouldTrans , transmissivityCap );
446- rgbTrans .z = reassignTransmissivity (rgbTrans .x , rgbTrans .z , rgbTrans .y , shouldTrans , transmissivityCap );
447- rgbTrans .y = gTransNew ;
448- rgbTrans .x = transmissivityCap ;
449- } else if (maxTrans == rgbTrans .y ) {
450- // Give excess transmission from green to red and blue
451- double rTransNew = reassignTransmissivity (rgbTrans .y , rgbTrans .x , rgbTrans .z , shouldTrans , transmissivityCap );
452- rgbTrans .z = reassignTransmissivity (rgbTrans .y , rgbTrans .z , rgbTrans .x , shouldTrans , transmissivityCap );
453- rgbTrans .x = rTransNew ;
454- rgbTrans .y = transmissivityCap ;
455- } else if (maxTrans == rgbTrans .z ) {
456- // Give excess transmission from blue to green and red
457- double gTransNew = reassignTransmissivity (rgbTrans .z , rgbTrans .y , rgbTrans .x , shouldTrans , transmissivityCap );
458- rgbTrans .x = reassignTransmissivity (rgbTrans .z , rgbTrans .x , rgbTrans .y , shouldTrans , transmissivityCap );
459- rgbTrans .y = gTransNew ;
460- rgbTrans .z = transmissivityCap ;
428+ Vector3 rgbTrans ;
429+ if (scene .fancierTranslucency ) {
430+ // Color-based transmission value
431+ double colorTrans = (ray .color .x + ray .color .y + ray .color .z ) / 3 ;
432+ // Total amount of light we want to transmit (overall transparency of texture)
433+ double shouldTrans = 1 - opacity ;
434+ // Amount of each color to transmit - default to overall transparency if RGB values add to 0 (e.g. regular glass)
435+ rgbTrans = new Vector3 (shouldTrans , shouldTrans , shouldTrans );
436+ if (colorTrans > 0 ) {
437+ // Amount to transmit of each color is scaled so the total transmitted amount matches the texture's transparency
438+ rgbTrans .set (ray .color .toVec3 ());
439+ rgbTrans .scale (shouldTrans / colorTrans );
461440 }
462- }
463- // Don't need to check for energy gain if transmissivity cap is 1
464- if (transmissivityCap > 1 ) {
465- double currentEnergy = rgbTrans .x * next .color .x + rgbTrans .y * next .color .y + rgbTrans .z * next .color .z ;
466- double nextEnergy = next .color .x + next .color .y + next .color .z ;
467- double energyRatio = nextEnergy / currentEnergy ;
468- // Normalize if there is net energy gain across all channels (more likely for higher transmissivityCap combined with high-saturation light source)
469- if (energyRatio < 1 ) {
470- rgbTrans .scale (energyRatio );
441+ double transmissivityCap = scene .transmissivityCap ;
442+ // Determine the color with the highest transmissivity
443+ double maxTrans = Math .max (rgbTrans .x , Math .max (rgbTrans .y , rgbTrans .z ));
444+ if (maxTrans > transmissivityCap ) {
445+ if (maxTrans == rgbTrans .x ) {
446+ // Give excess transmission from red to green and blue
447+ double gTransNew = reassignTransmissivity (rgbTrans .x , rgbTrans .y , rgbTrans .z , shouldTrans , transmissivityCap );
448+ rgbTrans .z = reassignTransmissivity (rgbTrans .x , rgbTrans .z , rgbTrans .y , shouldTrans , transmissivityCap );
449+ rgbTrans .y = gTransNew ;
450+ rgbTrans .x = transmissivityCap ;
451+ } else if (maxTrans == rgbTrans .y ) {
452+ // Give excess transmission from green to red and blue
453+ double rTransNew = reassignTransmissivity (rgbTrans .y , rgbTrans .x , rgbTrans .z , shouldTrans , transmissivityCap );
454+ rgbTrans .z = reassignTransmissivity (rgbTrans .y , rgbTrans .z , rgbTrans .x , shouldTrans , transmissivityCap );
455+ rgbTrans .x = rTransNew ;
456+ rgbTrans .y = transmissivityCap ;
457+ } else if (maxTrans == rgbTrans .z ) {
458+ // Give excess transmission from blue to green and red
459+ double gTransNew = reassignTransmissivity (rgbTrans .z , rgbTrans .y , rgbTrans .x , shouldTrans , transmissivityCap );
460+ rgbTrans .x = reassignTransmissivity (rgbTrans .z , rgbTrans .x , rgbTrans .y , shouldTrans , transmissivityCap );
461+ rgbTrans .y = gTransNew ;
462+ rgbTrans .z = transmissivityCap ;
463+ }
471464 }
465+ // Don't need to check for energy gain if transmissivity cap is 1
466+ if (transmissivityCap > 1 ) {
467+ double currentEnergy = rgbTrans .x * next .color .x + rgbTrans .y * next .color .y + rgbTrans .z * next .color .z ;
468+ double nextEnergy = next .color .x + next .color .y + next .color .z ;
469+ double energyRatio = nextEnergy / currentEnergy ;
470+ // Normalize if there is net energy gain across all channels (more likely for higher transmissivityCap combined with high-saturation light source)
471+ if (energyRatio < 1 ) {
472+ rgbTrans .scale (energyRatio );
473+ }
474+ }
475+ } else {
476+ // Old method (see https://github.com/chunky-dev/chunky/pull/1513)
477+ rgbTrans = new Vector3 (1 - opacity , 1 - opacity , 1 - opacity );
478+ rgbTrans .scaleAdd (opacity , ray .color .toVec3 ());
472479 }
473480 // Scale color based on next ray
474481 Vector4 outputColor = new Vector4 (0 , 0 , 0 , 0 );
0 commit comments