forked from bartvdbraak/blender
Fix #33177: OSL render difference with missing textures and HSV nodes.
This commit is contained in:
parent
ab1b5af08d
commit
fd619cd7f1
@ -43,6 +43,7 @@ struct OSLGlobals {
|
||||
|
||||
/* shading system */
|
||||
OSL::ShadingSystem *ss;
|
||||
OSL::TextureSystem *ts;
|
||||
OSLRenderServices *services;
|
||||
|
||||
/* shader states */
|
||||
|
@ -649,6 +649,80 @@ bool OSLRenderServices::has_userdata(ustring name, TypeDesc type, void *renderst
|
||||
return false; /* never called by OSL */
|
||||
}
|
||||
|
||||
bool OSLRenderServices::texture(ustring filename, TextureOpt &options,
|
||||
OSL::ShaderGlobals *sg,
|
||||
float s, float t, float dsdx, float dtdx,
|
||||
float dsdy, float dtdy, float *result)
|
||||
{
|
||||
OSL::TextureSystem *ts = kernel_globals->osl.ts;
|
||||
bool status = ts->texture(filename, options, s, t, dsdx, dtdx, dsdy, dtdy, result);
|
||||
|
||||
if(!status) {
|
||||
if(options.nchannels == 3 || options.nchannels == 4) {
|
||||
result[0] = 1.0f;
|
||||
result[1] = 0.0f;
|
||||
result[2] = 1.0f;
|
||||
|
||||
if(options.nchannels == 4)
|
||||
result[3] = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
bool OSLRenderServices::texture3d(ustring filename, TextureOpt &options,
|
||||
OSL::ShaderGlobals *sg, const OSL::Vec3 &P,
|
||||
const OSL::Vec3 &dPdx, const OSL::Vec3 &dPdy,
|
||||
const OSL::Vec3 &dPdz, float *result)
|
||||
{
|
||||
OSL::TextureSystem *ts = kernel_globals->osl.ts;
|
||||
bool status = ts->texture3d(filename, options, P, dPdx, dPdy, dPdz, result);
|
||||
|
||||
if(!status) {
|
||||
if(options.nchannels == 3 || options.nchannels == 4) {
|
||||
result[0] = 1.0f;
|
||||
result[1] = 0.0f;
|
||||
result[2] = 1.0f;
|
||||
|
||||
if(options.nchannels == 4)
|
||||
result[3] = 1.0f;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
bool OSLRenderServices::environment(ustring filename, TextureOpt &options,
|
||||
OSL::ShaderGlobals *sg, const OSL::Vec3 &R,
|
||||
const OSL::Vec3 &dRdx, const OSL::Vec3 &dRdy, float *result)
|
||||
{
|
||||
OSL::TextureSystem *ts = kernel_globals->osl.ts;
|
||||
bool status = ts->environment(filename, options, R, dRdx, dRdy, result);
|
||||
|
||||
if(!status) {
|
||||
if(options.nchannels == 3 || options.nchannels == 4) {
|
||||
result[0] = 1.0f;
|
||||
result[1] = 0.0f;
|
||||
result[2] = 1.0f;
|
||||
|
||||
if(options.nchannels == 4)
|
||||
result[3] = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
bool OSLRenderServices::get_texture_info(ustring filename, int subimage,
|
||||
ustring dataname,
|
||||
TypeDesc datatype, void *data)
|
||||
{
|
||||
OSL::TextureSystem *ts = kernel_globals->osl.ts;
|
||||
return ts->get_texture_info(filename, subimage, dataname, datatype, data);
|
||||
}
|
||||
|
||||
int OSLRenderServices::pointcloud_search(OSL::ShaderGlobals *sg, ustring filename, const OSL::Vec3 ¢er,
|
||||
float radius, int max_points, bool sort,
|
||||
size_t *out_indices, float *out_distances, int derivs_offset)
|
||||
|
@ -84,6 +84,23 @@ public:
|
||||
bool getmessage(OSL::ShaderGlobals *sg, ustring source, ustring name,
|
||||
TypeDesc type, void *val, bool derivatives);
|
||||
|
||||
bool texture(ustring filename, TextureOpt &options,
|
||||
OSL::ShaderGlobals *sg,
|
||||
float s, float t, float dsdx, float dtdx,
|
||||
float dsdy, float dtdy, float *result);
|
||||
|
||||
bool texture3d(ustring filename, TextureOpt &options,
|
||||
OSL::ShaderGlobals *sg, const OSL::Vec3 &P,
|
||||
const OSL::Vec3 &dPdx, const OSL::Vec3 &dPdy,
|
||||
const OSL::Vec3 &dPdz, float *result);
|
||||
|
||||
bool environment(ustring filename, TextureOpt &options,
|
||||
OSL::ShaderGlobals *sg, const OSL::Vec3 &R,
|
||||
const OSL::Vec3 &dRdx, const OSL::Vec3 &dRdy, float *result);
|
||||
|
||||
bool get_texture_info(ustring filename, int subimage,
|
||||
ustring dataname, TypeDesc datatype, void *data);
|
||||
|
||||
struct TraceData {
|
||||
Ray ray;
|
||||
Intersection isect;
|
||||
|
@ -20,32 +20,15 @@
|
||||
|
||||
shader node_brightness(
|
||||
color ColorIn = color(0.8, 0.8, 0.8),
|
||||
float Brightness = 0.0,
|
||||
float Bright = 0.0,
|
||||
float Contrast = 0.0,
|
||||
output color ColorOut = color(0.8, 0.8, 0.8))
|
||||
{
|
||||
float delta = Contrast * (1.0 / 200.0);
|
||||
float a = 1.0 - delta * 2.0;
|
||||
float b;
|
||||
float a = 1.0 + Contrast;
|
||||
float b = Bright - Contrast*0.5;
|
||||
|
||||
/* input value is a percentage */
|
||||
float bright_factor = Brightness / 100.0;
|
||||
|
||||
/*
|
||||
* The algorithm is by Werner D. Streidt
|
||||
* (http://visca.com/ffactory/archives/5-99/msg00021.html)
|
||||
* Extracted of OpenCV demhist.c
|
||||
*/
|
||||
|
||||
if (Contrast > 0.0) {
|
||||
a = (a < 0.0 ? 1.0 / a : 0.0);
|
||||
b = a * (bright_factor - delta);
|
||||
}
|
||||
else {
|
||||
delta *= -1.0;
|
||||
b = a * (bright_factor + delta);
|
||||
}
|
||||
|
||||
ColorOut = a * ColorIn + b;
|
||||
ColorOut[0] = max(a*ColorIn[0] + b, 0.0);
|
||||
ColorOut[1] = max(a*ColorIn[1] + b, 0.0);
|
||||
ColorOut[2] = max(a*ColorIn[2] + b, 0.0);
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,6 @@ shader node_hsv(
|
||||
color ColorIn = color(0.0, 0.0, 0.0),
|
||||
output color ColorOut = color(0.0, 0.0, 0.0))
|
||||
{
|
||||
float t = clamp(Fac, 0.0, 1.0);
|
||||
color Color = rgb_to_hsv(ColorIn);
|
||||
|
||||
// remember: fmod doesn't work for negative numbers
|
||||
@ -38,6 +37,6 @@ shader node_hsv(
|
||||
|
||||
Color = hsv_to_rgb(Color);
|
||||
|
||||
ColorOut = mix(Color, ColorIn, t);
|
||||
ColorOut = mix(ColorIn, Color, Fac);
|
||||
}
|
||||
|
||||
|
@ -88,6 +88,7 @@ void OSLShaderManager::device_update(Device *device, DeviceScene *dscene, Scene
|
||||
|
||||
/* setup shader engine */
|
||||
og->ss = ss;
|
||||
og->ts = ts;
|
||||
og->services = services;
|
||||
int background_id = scene->shader_manager->get_shader_id(scene->default_background);
|
||||
og->background_state = og->surface_state[background_id & SHADER_MASK];
|
||||
@ -118,6 +119,7 @@ void OSLShaderManager::device_free(Device *device, DeviceScene *dscene)
|
||||
/* clear shader engine */
|
||||
og->use = false;
|
||||
og->ss = NULL;
|
||||
og->ts = NULL;
|
||||
|
||||
og->surface_state.clear();
|
||||
og->volume_state.clear();
|
||||
@ -334,7 +336,7 @@ string OSLCompiler::compatible_name(ShaderNode *node, ShaderOutput *output)
|
||||
while((i = sname.find(" ")) != string::npos)
|
||||
sname.replace(i, 1, "");
|
||||
|
||||
/* if output exists with the same name, add "In" suffix */
|
||||
/* if input exists with the same name, add "Out" suffix */
|
||||
foreach(ShaderInput *input, node->inputs) {
|
||||
if (strcmp(input->name, output->name)==0) {
|
||||
sname += "Out";
|
||||
|
Loading…
Reference in New Issue
Block a user