/********************************************************************************** Persistence of Vision Ray Tracer Scene Description File File name : Clipka_Colour Saturation.mcr Version : 3.71 Description : colour saturation macro Date : 2016 Author : Clipka E-mail : http://news.povray.org/povray.advanced-users/thread/%3C57894ece%241%40news.povray.org%3E/ Copyright (C) 2016. All rights reserved. Use and/or modification of this scene is free, except for commercial purposes. Commercial distribution is not allowed without written permission from the author. **********************************************************************************/ // Render settings (right-click on a line below): // +w640 +h640 +am2 +a0.3 +bm2 +bs8 +wt6 #version 3.71; #ifndef(Standalone) #declare Standalone = on; #end //====================================================================== //Colour saturation variation code by Clipka (see explanation at end) //[povray.advanced-users 15-07-2016: Reverse engineering pigments and textures by BaldEagle]: #macro ColourSat(SatBoost, BrightBoost, Raw) #declare SB = SatBoost; // Saturation boost #declare VB = BrightBoost; // Brightness ("volume") boost #declare RawColour = srgb Raw; #declare SatColour = RawColour-SB; #declare MyColour = SatColour*(1+VB)*RawColour.gray/SatColour.gray; MyColour #end //====================================================================== #if (Standalone) global_settings { assumed_gamma 1.0 } #declare TileScale = 2; #declare SatBoost = 0.1; #declare BrightBoost = 0.0; //0 = no brightness change; >0 = brighter; <0 = darker //original texture: #declare MedTileTex0 = texture { pigment { cells color_map {//colours picked from roof images [0.1 srgb <220,158,106>/255] [0.2 srgb <217,177,126>/255] [0.3 srgb <228,215,173>/255] [0.4 srgb <219,152,100>/255] [0.5 srgb <166,120, 61>/255] [0.6 srgb <225,171,125>/255] [0.7 srgb <230,199,142>/255] [0.8 srgb <223,187,129>/255] [0.9 srgb <236,176,114>/255] [1.0 srgb <244,188,131>/255] } scale <1, 1, 2>*TileScale } normal { average normal_map { [1 granite 0.2 scale 0.01] [1 cells 2] } scale <1, 1, 2>*TileScale } finish { diffuse 1 specular 0.3 roughness 0.002 } scale <0.1, 0.2, 0.1>*0.6 } //saturation boosted texture: #declare MedTileTex1 = texture { pigment { cells color_map {//colours picked from roof images [0.1 ColourSat(SatBoost, BrightBoost, <220,158,106>/255)] [0.2 ColourSat(SatBoost, BrightBoost, <217,177,126>/255)] [0.3 ColourSat(SatBoost, BrightBoost, <228,215,173>/255)] [0.4 ColourSat(SatBoost, BrightBoost, <219,152,100>/255)] [0.5 ColourSat(SatBoost, BrightBoost, <166,120,61>/255)] [0.6 ColourSat(SatBoost, BrightBoost, <225,171,125>/255)] [0.7 ColourSat(SatBoost, BrightBoost, <230,199,142>/255)] [0.8 ColourSat(SatBoost, BrightBoost, <223,187,129>/255)] [0.9 ColourSat(SatBoost, BrightBoost, <236,176,114>/255)] [1.0 ColourSat(SatBoost, BrightBoost, <244,188,131>/255)] } scale <1, 1, 2>*TileScale } normal { average normal_map { [1 granite 0.2 scale 0.01] [1 cells 2] } scale <1, 1, 2>*TileScale } finish { diffuse 1 specular 0.3 roughness 0.002 } scale <0.1, 0.2, 0.1>*0.6 } //left: original texture: difference { plane { y, 0.0 texture {MedTileTex0} } plane { y, 0.001 rotate 90*z texture {pigment {rgbt 1}} } } //right: saturation boosted texture: difference { plane { y, 0.0 texture {MedTileTex1} } plane { y, 0.001 rotate -90*z texture {pigment {rgbt 1}} } } //====================================================================== #default {pigment {rgb <1,0,0>}} #default {finish {diffuse 1}} #include "colors.inc" //====================================================================== camera { location <0.0, 5.0, 0.0> direction 1.5*z right x*image_width/image_height look_at <0.0, 0.0, 0.0> } sky_sphere { pigment {colour srgb 0.99} } light_source { <0, 0, 0> color srgb <1, 1, 1> translate <0, 10, 0>*1000 } /* light_source { <0, 0, 0> color rgb <1, 1, 1>*0.3 translate <30, 30, -30>*1000 shadowless } */ #end //of Standalone //====================================================================== //====================================================================== /* BaldEagle: > I am having, and have had in the past, difficulty reproducing the colors in > sampled images in my renders. > > I was wondering if anyone has had success in sampling rgb values from images or > "rgb color picker" apps and getting good results in their renders. > using sRGB doesn't seem to help me much. Clipka: You have to remember that the colour you see in images is not a straightforward material colour, but a combination of (a) the material colour, (b) the surface finish, (c) the geometry, (d) the direct illumination from light sources, and (e) the indirect illumination via other objects. Presuming an overall white illumination, the most important factors will be: (1) Darkening from shadows and/or the light hitting the surface at a shallow angle. This corresponds to a mixing with black. (2) Brightening from (possibly very dull) highlights. This corresponds to a mixing with white. In combination, they correspond to a change in total brightness and desaturation. To counter this, you'll usually have to boost both the brightness by multiplying all channels by another constant value, and the saturation by subtracting another constant value from all channels. By how much, that's a thing you'll have to figure out by tweaking. Note that these changes need to be applied _after_ converting the picked colour values to linear colour space; this is especially true for the boosting of the saturation, which would otherwise cause a shift in hue. I haven't tested it, but you should be able to do it like this: #declare SB = 0.2; // Saturation boost #declare VB = 0.4; // Brightness ("volume") boost #declare MyColour = (( srgb <128,255,220>/255 )-SB)*(1+VB); Note that in this variant the saturation boost also affects the brightness, but the upside is that the formula remains simple enough to be written in one declaration statement, or even at the very place where the colour is actually used. If you are ok with something more complex but possibly easier to tweak, try the following: #declare SB = 0.2; // Saturation boost #declare VB = 0.2; // Brightness ("volume") boost #declare RawColour = srgb <128,255,220>/255; #declare SatColour = RawColour-SB; #declare MyColour = SatColour*(1+VB)*RawColour.gray/SatColour.gray; This should keep the general brightness unaffected by tweaks to the saturation. Indirect illumination from nearby colourful surfaces, or a general non-uniformity in the distribution of colours in the illumination (such as a sunny sky, with a yellowish sun and blue sky), may introduce additional challenges by also affecting the hue. Countering these may prove particularly challenging, and you may end up tweaking each colour channel individually. However, the above stable-brightness trick may help a bit with this. In any case, colours picked from a simple everyday photograph (as opposed to a photograph taken under carefully chosen lighting conditions) are typically only useful as a starting point, and will almost inevitably need a certain degree of tweaking. */