[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [57326] branches/soc-2013-dingto/intern/ cycles: Cycles / Code cleanup:
Thomas Dinges
blender at dingto.org
Mon Jun 10 02:01:52 CEST 2013
Revision: 57326
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57326
Author: dingto
Date: 2013-06-10 00:01:52 +0000 (Mon, 10 Jun 2013)
Log Message:
-----------
Cycles / Code cleanup:
* Move hsv and xyz color functions into the dedicated util files (util_color.h and node_color.h).
* svm_lerp moved into util_math.h and renamed to lerp_interp, as it's used for the wavelength node now as well.
Modified Paths:
--------------
branches/soc-2013-dingto/intern/cycles/kernel/shaders/node_color.h
branches/soc-2013-dingto/intern/cycles/kernel/shaders/node_sky_texture.osl
branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_hsv.h
branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_mix.h
branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_sky.h
branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_wavelength.h
branches/soc-2013-dingto/intern/cycles/util/util_color.h
branches/soc-2013-dingto/intern/cycles/util/util_math.h
Modified: branches/soc-2013-dingto/intern/cycles/kernel/shaders/node_color.h
===================================================================
--- branches/soc-2013-dingto/intern/cycles/kernel/shaders/node_color.h 2013-06-09 23:31:53 UTC (rev 57325)
+++ branches/soc-2013-dingto/intern/cycles/kernel/shaders/node_color.h 2013-06-10 00:01:52 UTC (rev 57326)
@@ -58,6 +58,26 @@
/* Color Operations */
+color xyY_to_xyz(float x, float y, float Y)
+{
+ float X, Z;
+
+ if (y != 0.0) X = (x / y) * Y;
+ else X = 0.0;
+
+ if (y != 0.0 && Y != 0.0) Z = ((1.0 - x - y) / y) * Y;
+ else Z = 0.0;
+
+ return color(X, Y, Z);
+}
+
+color xyz_to_rgb(float x, float y, float z)
+{
+ return color( 3.240479 * x + -1.537150 * y + -0.498535 * z,
+ -0.969256 * x + 1.875991 * y + 0.041556 * z,
+ 0.055648 * x + -0.204043 * y + 1.057311 * z);
+}
+
color rgb_to_hsv(color rgb)
{
float cmax, cmin, h, s, v, cdelta;
Modified: branches/soc-2013-dingto/intern/cycles/kernel/shaders/node_sky_texture.osl
===================================================================
--- branches/soc-2013-dingto/intern/cycles/kernel/shaders/node_sky_texture.osl 2013-06-09 23:31:53 UTC (rev 57325)
+++ branches/soc-2013-dingto/intern/cycles/kernel/shaders/node_sky_texture.osl 2013-06-10 00:01:52 UTC (rev 57326)
@@ -17,6 +17,7 @@
*/
#include "stdosl.h"
+#include "node_color.h"
struct KernelSunSky {
/* sun direction in spherical and cartesian */
@@ -28,26 +29,6 @@
float perez_Y[5], perez_x[5], perez_y[5];
};
-color xyY_to_xyz(float x, float y, float Y)
-{
- float X, Z;
-
- if (y != 0.0) X = (x / y) * Y;
- else X = 0.0;
-
- if (y != 0.0 && Y != 0.0) Z = ((1.0 - x - y) / y) * Y;
- else Z = 0.0;
-
- return color(X, Y, Z);
-}
-
-color xyz_to_rgb(float x, float y, float z)
-{
- return color( 3.240479 * x + -1.537150 * y + -0.498535 * z,
- -0.969256 * x + 1.875991 * y + 0.041556 * z,
- 0.055648 * x + -0.204043 * y + 1.057311 * z);
-}
-
float sky_angle_between(float thetav, float phiv, float theta, float phi)
{
float cospsi = sin(thetav) * sin(theta) * cos(phi - phiv) + cos(thetav) * cos(theta);
Modified: branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_hsv.h
===================================================================
--- branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_hsv.h 2013-06-09 23:31:53 UTC (rev 57325)
+++ branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_hsv.h 2013-06-10 00:01:52 UTC (rev 57326)
@@ -21,80 +21,6 @@
CCL_NAMESPACE_BEGIN
-__device float3 rgb_to_hsv(float3 rgb)
-{
- float cmax, cmin, h, s, v, cdelta;
- float3 c;
-
- cmax = fmaxf(rgb.x, fmaxf(rgb.y, rgb.z));
- cmin = min(rgb.x, min(rgb.y, rgb.z));
- cdelta = cmax - cmin;
-
- v = cmax;
-
- if(cmax != 0.0f) {
- s = cdelta/cmax;
- }
- else {
- s = 0.0f;
- h = 0.0f;
- }
-
- if(s == 0.0f) {
- h = 0.0f;
- }
- else {
- float3 cmax3 = make_float3(cmax, cmax, cmax);
- c = (cmax3 - rgb)/cdelta;
-
- if(rgb.x == cmax) h = c.z - c.y;
- else if(rgb.y == cmax) h = 2.0f + c.x - c.z;
- else h = 4.0f + c.y - c.x;
-
- h /= 6.0f;
-
- if(h < 0.0f)
- h += 1.0f;
- }
-
- return make_float3(h, s, v);
-}
-
-__device float3 hsv_to_rgb(float3 hsv)
-{
- float i, f, p, q, t, h, s, v;
- float3 rgb;
-
- h = hsv.x;
- s = hsv.y;
- v = hsv.z;
-
- if(s == 0.0f) {
- rgb = make_float3(v, v, v);
- }
- else {
- if(h == 1.0f)
- h = 0.0f;
-
- h *= 6.0f;
- i = floorf(h);
- f = h - i;
- rgb = make_float3(f, f, f);
- p = v*(1.0f-s);
- q = v*(1.0f-(s*f));
- t = v*(1.0f-(s*(1.0f-f)));
-
- if(i == 0.0f) rgb = make_float3(v, t, p);
- else if(i == 1.0f) rgb = make_float3(q, v, p);
- else if(i == 2.0f) rgb = make_float3(p, v, t);
- else if(i == 3.0f) rgb = make_float3(p, q, v);
- else if(i == 4.0f) rgb = make_float3(t, p, v);
- else rgb = make_float3(v, p, q);
- }
-
- return rgb;
-}
-
__device void svm_node_hsv(KernelGlobals *kg, ShaderData *sd, float *stack, uint in_color_offset, uint fac_offset, uint out_color_offset, int *offset)
{
/* read extra data */
Modified: branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_mix.h
===================================================================
--- branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_mix.h 2013-06-09 23:31:53 UTC (rev 57325)
+++ branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_mix.h 2013-06-10 00:01:52 UTC (rev 57326)
@@ -16,28 +16,21 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include "svm_hsv.h"
-
CCL_NAMESPACE_BEGIN
-__device float3 svm_lerp(const float3 a, const float3 b, float t)
-{
- return (a * (1.0f - t) + b * t);
-}
-
__device float3 svm_mix_blend(float t, float3 col1, float3 col2)
{
- return svm_lerp(col1, col2, t);
+ return lerp_interp(col1, col2, t);
}
__device float3 svm_mix_add(float t, float3 col1, float3 col2)
{
- return svm_lerp(col1, col1 + col2, t);
+ return lerp_interp(col1, col1 + col2, t);
}
__device float3 svm_mix_mul(float t, float3 col1, float3 col2)
{
- return svm_lerp(col1, col1 * col2, t);
+ return lerp_interp(col1, col1 * col2, t);
}
__device float3 svm_mix_screen(float t, float3 col1, float3 col2)
@@ -75,7 +68,7 @@
__device float3 svm_mix_sub(float t, float3 col1, float3 col2)
{
- return svm_lerp(col1, col1 - col2, t);
+ return lerp_interp(col1, col1 - col2, t);
}
__device float3 svm_mix_div(float t, float3 col1, float3 col2)
@@ -93,7 +86,7 @@
__device float3 svm_mix_diff(float t, float3 col1, float3 col2)
{
- return svm_lerp(col1, fabs(col1 - col2), t);
+ return lerp_interp(col1, fabs(col1 - col2), t);
}
__device float3 svm_mix_dark(float t, float3 col1, float3 col2)
@@ -191,7 +184,7 @@
hsv.x = hsv2.x;
float3 tmp = hsv_to_rgb(hsv);
- outcol = svm_lerp(outcol, tmp, t);
+ outcol = lerp_interp(outcol, tmp, t);
}
return outcol;
@@ -238,7 +231,7 @@
hsv.y = hsv2.y;
float3 tmp = hsv_to_rgb(hsv);
- outcol = svm_lerp(outcol, tmp, t);
+ outcol = lerp_interp(outcol, tmp, t);
}
return outcol;
Modified: branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_sky.h
===================================================================
--- branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_sky.h 2013-06-09 23:31:53 UTC (rev 57325)
+++ branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_sky.h 2013-06-10 00:01:52 UTC (rev 57326)
@@ -18,26 +18,6 @@
CCL_NAMESPACE_BEGIN
-__device float3 xyY_to_xyz(float x, float y, float Y)
-{
- float X, Z;
-
- if(y != 0.0f) X = (x / y) * Y;
- else X = 0.0f;
-
- if(y != 0.0f && Y != 0.0f) Z = (1.0f - x - y) / y * Y;
- else Z = 0.0f;
-
- return make_float3(X, Y, Z);
-}
-
-__device float3 xyz_to_rgb(float x, float y, float z)
-{
- return make_float3(3.240479f * x + -1.537150f * y + -0.498535f * z,
- -0.969256f * x + 1.875991f * y + 0.041556f * z,
- 0.055648f * x + -0.204043f * y + 1.057311f * z);
-}
-
/*
* "A Practical Analytic Model for Daylight"
* A. J. Preetham, Peter Shirley, Brian Smits
Modified: branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_wavelength.h
===================================================================
--- branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_wavelength.h 2013-06-09 23:31:53 UTC (rev 57325)
+++ branches/soc-2013-dingto/intern/cycles/kernel/svm/svm_wavelength.h 2013-06-10 00:01:52 UTC (rev 57326)
@@ -34,19 +34,6 @@
/* Wavelength to RGB */
-/* ToDo: Move these 2 functions to an util file */
-__device float3 xyz_to_rgb_wave(float x, float y, float z)
-{
- return make_float3(3.240479f * x + -1.537150f * y + -0.498535f * z,
- -0.969256f * x + 1.875991f * y + 0.041556f * z,
- 0.055648f * x + -0.204043f * y + 1.057311f * z);
-}
-
-__device float3 wavelength_lerp(const float3 a, const float3 b, float t)
-{
- return (a * (1.0f - t) + b * t);
-}
-
__device void svm_node_wavelength(ShaderData *sd, float *stack, uint wavelength, uint color_out)
{
// CIE colour matching functions xBar, yBar, and zBar for
@@ -96,10 +83,10 @@
else {
ii -= i;
float *c = cie_colour_match[i];
- rgb = wavelength_lerp(make_float3(c[0], c[1], c[2]), make_float3(c[3], c[4], c[5]), ii);
+ rgb = lerp_interp(make_float3(c[0], c[1], c[2]), make_float3(c[3], c[4], c[5]), ii);
}
- rgb = xyz_to_rgb_wave(rgb.x, rgb.y, rgb.z);
+ rgb = xyz_to_rgb(rgb.x, rgb.y, rgb.z);
rgb *= 1.0/2.52; // Empirical scale from lg to make all comps <= 1
/* Clamp to Zero if values are smaller */
Modified: branches/soc-2013-dingto/intern/cycles/util/util_color.h
===================================================================
--- branches/soc-2013-dingto/intern/cycles/util/util_color.h 2013-06-09 23:31:53 UTC (rev 57325)
+++ branches/soc-2013-dingto/intern/cycles/util/util_color.h 2013-06-10 00:01:52 UTC (rev 57326)
@@ -40,6 +40,100 @@
return 1.055f * powf(c, 1.0f / 2.4f) - 0.055f;
}
+__device float3 rgb_to_hsv(float3 rgb)
+{
+ float cmax, cmin, h, s, v, cdelta;
+ float3 c;
+
+ cmax = fmaxf(rgb.x, fmaxf(rgb.y, rgb.z));
+ cmin = min(rgb.x, min(rgb.y, rgb.z));
+ cdelta = cmax - cmin;
+
+ v = cmax;
+
+ if(cmax != 0.0f) {
+ s = cdelta/cmax;
+ }
+ else {
+ s = 0.0f;
+ h = 0.0f;
+ }
+
+ if(s == 0.0f) {
+ h = 0.0f;
+ }
+ else {
+ float3 cmax3 = make_float3(cmax, cmax, cmax);
+ c = (cmax3 - rgb)/cdelta;
+
+ if(rgb.x == cmax) h = c.z - c.y;
+ else if(rgb.y == cmax) h = 2.0f + c.x - c.z;
+ else h = 4.0f + c.y - c.x;
+
+ h /= 6.0f;
+
+ if(h < 0.0f)
+ h += 1.0f;
+ }
+
+ return make_float3(h, s, v);
+}
+
+__device float3 hsv_to_rgb(float3 hsv)
+{
+ float i, f, p, q, t, h, s, v;
+ float3 rgb;
+
+ h = hsv.x;
+ s = hsv.y;
+ v = hsv.z;
+
+ if(s == 0.0f) {
+ rgb = make_float3(v, v, v);
+ }
+ else {
+ if(h == 1.0f)
+ h = 0.0f;
+
+ h *= 6.0f;
+ i = floorf(h);
+ f = h - i;
+ rgb = make_float3(f, f, f);
+ p = v*(1.0f-s);
+ q = v*(1.0f-(s*f));
+ t = v*(1.0f-(s*(1.0f-f)));
+
+ if(i == 0.0f) rgb = make_float3(v, t, p);
+ else if(i == 1.0f) rgb = make_float3(q, v, p);
+ else if(i == 2.0f) rgb = make_float3(p, v, t);
+ else if(i == 3.0f) rgb = make_float3(p, q, v);
+ else if(i == 4.0f) rgb = make_float3(t, p, v);
+ else rgb = make_float3(v, p, q);
+ }
+
+ return rgb;
+}
+
+__device float3 xyY_to_xyz(float x, float y, float Y)
+{
+ float X, Z;
+
+ if(y != 0.0f) X = (x / y) * Y;
+ else X = 0.0f;
+
+ if(y != 0.0f && Y != 0.0f) Z = (1.0f - x - y) / y * Y;
+ else Z = 0.0f;
+
+ return make_float3(X, Y, Z);
+}
+
+__device float3 xyz_to_rgb(float x, float y, float z)
+{
+ return make_float3(3.240479f * x + -1.537150f * y + -0.498535f * z,
+ -0.969256f * x + 1.875991f * y + 0.041556f * z,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list