xyYToRGB.glsl   xyYToRGB.glsl 
skipping to change at line 19 skipping to change at line 19
// Variables for the color computation // Variables for the color computation
uniform highp vec3 sunPos; uniform highp vec3 sunPos;
uniform mediump float term_x, Ax, Bx, Cx, Dx, Ex; uniform mediump float term_x, Ax, Bx, Cx, Dx, Ex;
uniform mediump float term_y, Ay, By, Cy, Dy, Ey; uniform mediump float term_y, Ay, By, Cy, Dy, Ey;
// The current projection matrix // The current projection matrix
uniform mediump mat4 projectionMatrix; uniform mediump mat4 projectionMatrix;
// Contains the 2d position of the point on the screen (before multiplicati on by the projection matrix) // Contains the 2d position of the point on the screen (before multiplicati on by the projection matrix)
attribute mediump vec2 vertex; attribute mediump vec2 skyVertex;
// Contains the r,g,b,Y (luminosity) components. // Contains the r,g,b,Y (luminosity) components.
attribute highp vec4 color; attribute highp vec4 skyColor;
// The output variable passed to the fragment shader // The output variable passed to the fragment shader
varying mediump vec4 resultSkyColor; varying mediump vec3 resultSkyColor;
void main() void main()
{ {
gl_Position = projectionMatrix*vec4(vertex, 0., 1.); gl_Position = projectionMatrix*vec4(skyVertex, 0., 1.);
highp vec4 color = skyColor;
// Must be a separate variable due to Intel drivers
vec4 tempColor = color;
//////////////////////////////////////////////////////////////////// /////// //////////////////////////////////////////////////////////////////// ///////
// First compute the xy color component // First compute the xy color component
// color contains the unprojected vertex position in r,g,b // color contains the unprojected vertex position in r,g,b
// + the Y (luminance) component of the color in the alpha channel // + the Y (luminance) component of the color in the alpha channel
if (tempColor[3]>0.01) if (color[3]>0.01)
{ {
highp float cosDistSunq = sunPos[0]*tempColor[0] + sunPos[1] *tempColor[1] + sunPos[2]*tempColor[2]; highp float cosDistSunq = sunPos[0]*color[0] + sunPos[1]*col or[1] + sunPos[2]*color[2];
highp float distSun=acos(cosDistSunq); highp float distSun=acos(cosDistSunq);
highp float oneOverCosZenithAngle = (tempColor[2]==0.) ? 999 9999999999. : 1. / tempColor[2]; highp float oneOverCosZenithAngle = (color[2]==0.) ? 9999999 999999. : 1. / color[2];
cosDistSunq*=cosDistSunq; cosDistSunq*=cosDistSunq;
tempColor[0] = term_x * (1. + Ax * exp(Bx*oneOverCosZenithAn color[0] = term_x * (1. + Ax * exp(Bx*oneOverCosZenithAngle)
gle))* (1. + Cx * exp(Dx*distSun) + Ex * cosDistSunq); )* (1. + Cx * exp(Dx*distSun) + Ex * cosDistSunq);
tempColor[1] = term_y * (1. + Ay * exp(By*oneOverCosZenithAn color[1] = term_y * (1. + Ay * exp(By*oneOverCosZenithAngle)
gle))* (1. + Cy * exp(Dy*distSun) + Ey * cosDistSunq); )* (1. + Cy * exp(Dy*distSun) + Ey * cosDistSunq);
if (tempColor[0] < 0. || tempColor[1] < 0.) if (color[0] < 0. || color[1] < 0.)
{ {
tempColor[0] = 0.25; color[0] = 0.25;
tempColor[1] = 0.25; color[1] = 0.25;
} }
} }
else else
{ {
tempColor[0] = 0.25; color[0] = 0.25;
tempColor[1] = 0.25; color[1] = 0.25;
} }
tempColor[2]=tempColor[3]; color[2]=color[3];
tempColor[3]=1.; color[3]=1.;
//////////////////////////////////////////////////////////////////// /////// //////////////////////////////////////////////////////////////////// ///////
// Now we have the xyY components in color, need to convert to RGB // Now we have the xyY components in color, need to convert to RGB
// 1. Hue conversion // 1. Hue conversion
// if log10Y>0.6, photopic vision only (with the cones, colors are s een) // if log10Y>0.6, photopic vision only (with the cones, colors are s een)
// else scotopic vision if log10Y<-2 (with the rods, no colors, ever ything blue), // else scotopic vision if log10Y<-2 (with the rods, no colors, ever ything blue),
// else mesopic vision (with rods and cones, transition state) // else mesopic vision (with rods and cones, transition state)
if (tempColor[2] <= 0.01) if (color[2] <= 0.01)
{ {
// special case for s = 0 (x=0.25, y=0.25) // special case for s = 0 (x=0.25, y=0.25)
tempColor[2] *= 0.5121445; color[2] *= 0.5121445;
tempColor[2] = pow(tempColor[2]*pi*0.0001, alphaWaOverAlphaD color[2] = pow(abs(color[2]*pi*0.0001), alphaWaOverAlphaDa*o
a*oneOverGamma)* term2TimesOneOverMaxdLpOneOverGamma; neOverGamma)* term2TimesOneOverMaxdLpOneOverGamma;
tempColor[0] = 0.787077*tempColor[2]; color[0] = 0.787077*color[2];
tempColor[1] = 0.9898434*tempColor[2]; color[1] = 0.9898434*color[2];
tempColor[2] *= 1.9256125; color[2] *= 1.9256125;
resultSkyColor = tempColor*brightnessScale; resultSkyColor = color.xyz*brightnessScale;
} }
else else
{ {
if (tempColor[2]<3.9810717055349722) if (color[2]<3.9810717055349722)
{ {
// Compute s, ratio between scotopic and photopic vi sion // Compute s, ratio between scotopic and photopic vi sion
float op = (log(tempColor[2])/ln10 + 2.)/2.6; float op = (log(color[2])/ln10 + 2.)/2.6;
float s = op * op *(3. - 2. * op); float s = op * op *(3. - 2. * op);
// Do the blue shift for scotopic vision simulation (night vision) [3] // Do the blue shift for scotopic vision simulation (night vision) [3]
// The "night blue" is x,y(0.25, 0.25) // The "night blue" is x,y(0.25, 0.25)
tempColor[0] = (1. - s) * 0.25 + s * tempColor[0]; color[0] = (1. - s) * 0.25 + s * color[0]; // A
// Add scotopic + photopic components dd scotopic + photopic components
tempColor[1] = (1. - s) * 0.25 + s * tempColor[1]; color[1] = (1. - s) * 0.25 + s * color[1]; // A
// Add scotopic + photopic components dd scotopic + photopic components
// Take into account the scotopic luminance approxim ated by V [3] [4] // Take into account the scotopic luminance approxim ated by V [3] [4]
float V = tempColor[2] * (1.33 * (1. + tempColor[1] float V = color[2] * (1.33 * (1. + color[1] / color[
/ tempColor[0] + tempColor[0] * (1. - tempColor[0] - tempColor[1])) - 1.68) 0] + color[0] * (1. - color[0] - color[1])) - 1.68);
; color[2] = 0.4468 * (1. - s) * V + s * color[2];
tempColor[2] = 0.4468 * (1. - s) * V + s * tempColor
[2];
} }
// 2. Adapt the luminance value and scale it to fit in the R GB range [2] // 2. Adapt the luminance value and scale it to fit in the R GB range [2]
// tempColor[2] = std::pow(adaptLuminanceScaled(tempColor[2] // color[2] = std::pow(adaptLuminanceScaled(color[2]), oneOv
), oneOverGamma); erGamma);
tempColor[2] = pow(tempColor[2]*pi*0.0001, alphaWaOverAlphaD color[2] = pow(abs(color[2]*pi*0.0001), alphaWaOverAlphaDa*o
a*oneOverGamma)* term2TimesOneOverMaxdLpOneOverGamma; neOverGamma)* term2TimesOneOverMaxdLpOneOverGamma;
// Convert from xyY to XZY // Convert from xyY to XZY
// Use a XYZ to Adobe RGB (1998) matrix which uses a D65 ref erence white // Use a XYZ to Adobe RGB (1998) matrix which uses a D65 ref erence white
mediump vec3 tmp = vec3(tempColor[0] * tempColor[2] / tempCo mediump vec3 tmp = vec3(color[0] * color[2] / color[1], colo
lor[1], tempColor[2], (1. - tempColor[0] - tempColor[1]) * tempColor[2] / t r[2], (1. - color[0] - color[1]) * color[2] / color[1]);
empColor[1]); resultSkyColor = vec3(2.04148*tmp.x-0.564977*tmp.y-0.344713*
resultSkyColor = vec4(2.04148*tmp.x-0.564977*tmp.y-0.344713* tmp.z, -0.969258*tmp.x+1.87599*tmp.y+0.0415557*tmp.z, 0.0134455*tmp.x-0.118
tmp.z, -0.969258*tmp.x+1.87599*tmp.y+0.0415557*tmp.z, 0.0134455*tmp.x-0.118 373*tmp.y+1.01527*tmp.z);
373*tmp.y+1.01527*tmp.z, 1.);
resultSkyColor*=brightnessScale; resultSkyColor*=brightnessScale;
} }
} }
 End of changes. 19 change blocks. 
50 lines changed or deleted 45 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/