forked from bartvdbraak/blender
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:
parent
2390a2657e
commit
21964e6538
@ -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
|
||||
|
44
intern/cycles/kernel/osl/nodes/node_rgb_ramp.osl
Normal file
44
intern/cycles/kernel/osl/nodes/node_rgb_ramp.osl
Normal 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];
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -2768,6 +2768,19 @@ void RGBRampNode::compile(SVMCompiler& compiler)
|
||||
|
||||
void RGBRampNode::compile(OSLCompiler& compiler)
|
||||
{
|
||||
/* OSL shader only takes separate RGB and A array, split the RGBA base array */
|
||||
/* NB: cycles float3 type is actually 4 floats! need to use an explicit array */
|
||||
float ramp_color[RAMP_TABLE_SIZE][3];
|
||||
float ramp_alpha[RAMP_TABLE_SIZE];
|
||||
for (int i = 0; i < RAMP_TABLE_SIZE; ++i) {
|
||||
ramp_color[i][0] = ramp[i].x;
|
||||
ramp_color[i][1] = ramp[i].y;
|
||||
ramp_color[i][2] = ramp[i].z;
|
||||
ramp_alpha[i] = ramp[i].w;
|
||||
}
|
||||
compiler.parameter_color_array("ramp_color", ramp_color, RAMP_TABLE_SIZE);
|
||||
compiler.parameter_array("ramp_alpha", ramp_alpha, RAMP_TABLE_SIZE);
|
||||
|
||||
compiler.add(this, "node_rgb_ramp");
|
||||
}
|
||||
|
||||
|
@ -309,6 +309,70 @@ void OSLCompiler::parameter(const char *name, const Transform& tfm)
|
||||
ss->Parameter(name, TypeDesc::TypeMatrix, (float*)&tfm);
|
||||
}
|
||||
|
||||
void OSLCompiler::parameter_array(const char *name, const float f[], int arraylen)
|
||||
{
|
||||
OSL::ShadingSystem *ss = (OSL::ShadingSystem*)shadingsys;
|
||||
TypeDesc type = TypeDesc::TypeFloat;
|
||||
type.arraylen = arraylen;
|
||||
ss->Parameter(name, type, f);
|
||||
}
|
||||
|
||||
void OSLCompiler::parameter_color_array(const char *name, const float f[][3], int arraylen)
|
||||
{
|
||||
OSL::ShadingSystem *ss = (OSL::ShadingSystem*)shadingsys;
|
||||
TypeDesc type = TypeDesc::TypeColor;
|
||||
type.arraylen = arraylen;
|
||||
ss->Parameter(name, type, f);
|
||||
}
|
||||
|
||||
void OSLCompiler::parameter_vector_array(const char *name, const float f[][3], int arraylen)
|
||||
{
|
||||
OSL::ShadingSystem *ss = (OSL::ShadingSystem*)shadingsys;
|
||||
TypeDesc type = TypeDesc::TypeVector;
|
||||
type.arraylen = arraylen;
|
||||
ss->Parameter(name, type, f);
|
||||
}
|
||||
|
||||
void OSLCompiler::parameter_normal_array(const char *name, const float f[][3], int arraylen)
|
||||
{
|
||||
OSL::ShadingSystem *ss = (OSL::ShadingSystem*)shadingsys;
|
||||
TypeDesc type = TypeDesc::TypeNormal;
|
||||
type.arraylen = arraylen;
|
||||
ss->Parameter(name, type, f);
|
||||
}
|
||||
|
||||
void OSLCompiler::parameter_point_array(const char *name, const float f[][3], int arraylen)
|
||||
{
|
||||
OSL::ShadingSystem *ss = (OSL::ShadingSystem*)shadingsys;
|
||||
TypeDesc type = TypeDesc::TypePoint;
|
||||
type.arraylen = arraylen;
|
||||
ss->Parameter(name, type, f);
|
||||
}
|
||||
|
||||
void OSLCompiler::parameter_array(const char *name, const int f[], int arraylen)
|
||||
{
|
||||
OSL::ShadingSystem *ss = (OSL::ShadingSystem*)shadingsys;
|
||||
TypeDesc type = TypeDesc::TypeInt;
|
||||
type.arraylen = arraylen;
|
||||
ss->Parameter(name, type, f);
|
||||
}
|
||||
|
||||
void OSLCompiler::parameter_array(const char *name, const char * const s[], int arraylen)
|
||||
{
|
||||
OSL::ShadingSystem *ss = (OSL::ShadingSystem*)shadingsys;
|
||||
TypeDesc type = TypeDesc::TypeString;
|
||||
type.arraylen = arraylen;
|
||||
ss->Parameter(name, type, s);
|
||||
}
|
||||
|
||||
void OSLCompiler::parameter_array(const char *name, const Transform tfm[], int arraylen)
|
||||
{
|
||||
OSL::ShadingSystem *ss = (OSL::ShadingSystem*)shadingsys;
|
||||
TypeDesc type = TypeDesc::TypeMatrix;
|
||||
type.arraylen = arraylen;
|
||||
ss->Parameter(name, type, (const float *)tfm);
|
||||
}
|
||||
|
||||
void OSLCompiler::find_dependencies(set<ShaderNode*>& dependencies, ShaderInput *input)
|
||||
{
|
||||
ShaderNode *node = (input->link)? input->link->parent: NULL;
|
||||
|
@ -79,6 +79,15 @@ public:
|
||||
void parameter(const char *name, ustring str);
|
||||
void parameter(const char *name, const Transform& tfm);
|
||||
|
||||
void parameter_array(const char *name, const float f[], int arraylen);
|
||||
void parameter_color_array(const char *name, const float f[][3], int arraylen);
|
||||
void parameter_vector_array(const char *name, const float f[][3], int arraylen);
|
||||
void parameter_normal_array(const char *name, const float f[][3], int arraylen);
|
||||
void parameter_point_array(const char *name, const float f[][3], int arraylen);
|
||||
void parameter_array(const char *name, const int f[], int arraylen);
|
||||
void parameter_array(const char *name, const char * const s[], int arraylen);
|
||||
void parameter_array(const char *name, const Transform tfm[], int arraylen);
|
||||
|
||||
ShaderType output_type() { return current_type; }
|
||||
|
||||
bool background;
|
||||
|
Loading…
Reference in New Issue
Block a user