OSL implementation of RGB ramp node.

The sampled color ramp data is passed to OSL as a color array. This has to be done as actual float[3] array though, since the Cycles float3 type actually contains 4 floats, leading to shifting color components in the array.

Additional parameter set functions for arrays have been added to the Cycles OSL interface for this purpose.
This commit is contained in:
Lukas Toenne
2012-09-15 15:41:37 +00:00
parent 2390a2657e
commit 21964e6538
6 changed files with 134 additions and 0 deletions

View File

@@ -43,6 +43,7 @@ set(SRC_OSL
node_output_surface.osl
node_output_volume.osl
node_particle_info.osl
node_rgb_ramp.osl
node_separate_rgb.osl
node_sky_texture.osl
node_texture_coordinate.osl

View File

@@ -0,0 +1,44 @@
/*
* Copyright 2011, Blender Foundation.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "stdosl.h"
#include "oslutil.h"
shader node_rgb_ramp(
color ramp_color[RAMP_TABLE_SIZE] = {0.0},
float ramp_alpha[RAMP_TABLE_SIZE] = {0.0},
float Fac = 0.0,
output color Color = color(0.0, 0.0, 0.0),
output float Alpha = 1.0
)
{
float f = clamp(Fac, 0.0, 1.0)*(RAMP_TABLE_SIZE-1);
int i = (int)f;
float t = f - (float)i;
Color = ramp_color[i];
Alpha = ramp_alpha[i];
if (t > 0.0) {
Color = (1.0 - t)*Color + t*ramp_color[i+1];
Alpha = (1.0 - t)*Alpha + t*ramp_alpha[i+1];
}
}

View File

@@ -29,6 +29,9 @@
#ifndef CCL_OSLUTIL_H
#define CCL_OSLUTIL_H
/* NB: must match the value in kernel_types.h */
#define RAMP_TABLE_SIZE 256
// Return wireframe opacity factor [0, 1] given a geometry type in
// ("triangles", "polygons" or "patches"), and a line_width in raster
// or world space depending on the last (raster) boolean argument.