Fix cycles OSL missing support for texture mapping paramaters found in texture

properties tab.
This commit is contained in:
Brecht Van Lommel 2012-11-20 17:40:10 +00:00
parent a80b0915c7
commit ab1b5af08d
17 changed files with 159 additions and 35 deletions

@ -58,6 +58,8 @@ float brick(point p, float mortar_size, float bias,
}
shader node_brick_texture(
int use_mapping = 0,
matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
float Offset = 0.5,
int OffsetFrequency = 2,
float Squash = 1.0,
@ -74,10 +76,15 @@ shader node_brick_texture(
output float Fac = 0.0,
output color Color = color(0.2, 0.2, 0.2))
{
point p = Vector;
if (use_mapping)
p = transform(mapping, p);
float tint = 0.0;
color Col = Color1;
Fac = brick(Vector * Scale, MortarSize, Bias, BrickWidth, RowHeight,
Fac = brick(p * Scale, MortarSize, Bias, BrickWidth, RowHeight,
Offset, OffsetFrequency, Squash, SquashFrequency, tint);
if (Fac != 1.0) {

@ -40,6 +40,8 @@ float checker(point p)
}
shader node_checker_texture(
int use_mapping = 0,
matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
float Scale = 5.0,
point Vector = P,
color Color1 = color(0.8, 0.8, 0.8),
@ -47,7 +49,12 @@ shader node_checker_texture(
output float Fac = 0.0,
output color Color = color(0.0, 0.0, 0.0))
{
Fac = checker(Vector * Scale);
point p = Vector;
if (use_mapping)
p = transform(mapping, p);
Fac = checker(p * Scale);
if (Fac == 1.0) {
Color = Color1;
}

@ -40,6 +40,8 @@ vector environment_texture_direction_to_mirrorball(vector dir) {
}
shader node_environment_texture(
int use_mapping = 0,
matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
vector Vector = P,
string filename = "",
string projection = "Equirectangular",
@ -47,16 +49,20 @@ shader node_environment_texture(
output color Color = color(0.0, 0.0, 0.0),
output float Alpha = 1.0)
{
vector Vec = normalize(Vector);
vector p = Vector;
if (projection == "Equirectangular") {
Vec = environment_texture_direction_to_equirectangular(Vec);
}
else {
Vec = environment_texture_direction_to_mirrorball(Vec);
}
if (use_mapping)
p = transform(mapping, p);
p = normalize(p);
Color = (color)texture(filename, Vec[0], 1.0 - Vec[1], "wrap", "periodic", "alpha", Alpha);
if (projection == "Equirectangular")
p = environment_texture_direction_to_equirectangular(p);
else
p = environment_texture_direction_to_mirrorball(p);
/* todo: use environment for better texture filtering of equirectangular */
Color = (color)texture(filename, p[0], 1.0 - p[1], "wrap", "periodic", "alpha", Alpha);
if (color_space == "sRGB")
Color = color_srgb_to_scene_linear(Color);

@ -63,12 +63,19 @@ float gradient(point p, string type)
}
shader node_gradient_texture(
int use_mapping = 0,
matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
string Type = "Linear",
point Vector = P,
output float Fac = 0.0,
output color Color = color(0.0, 0.0, 0.0))
{
Fac = gradient(Vector, Type);
point p = Vector;
if (use_mapping)
p = transform(mapping, p);
Fac = gradient(p, Type);
Color = color(Fac, Fac, Fac);
}

@ -30,6 +30,8 @@ color image_texture_lookup(string filename, string color_space, float u, float v
}
shader node_image_texture(
int use_mapping = 0,
matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
point Vector = P,
string filename = "",
string color_space = "sRGB",
@ -38,8 +40,13 @@ shader node_image_texture(
output color Color = color(0.0, 0.0, 0.0),
output float Alpha = 1.0)
{
point p = Vector;
if (use_mapping)
p = transform(mapping, p);
if (projection == "Flat") {
Color = image_texture_lookup(filename, color_space, Vector[0], Vector[1], Alpha);
Color = image_texture_lookup(filename, color_space, p[0], p[1], Alpha);
}
else if (projection == "Box") {
/* object space normal */
@ -104,15 +111,15 @@ shader node_image_texture(
float tmp_alpha;
if (weight[0] > 0.0) {
Color += weight[0]*image_texture_lookup(filename, color_space, Vector[1], Vector[2], tmp_alpha);
Color += weight[0]*image_texture_lookup(filename, color_space, p[1], p[2], tmp_alpha);
Alpha += weight[0]*tmp_alpha;
}
if (weight[1] > 0.0) {
Color += weight[1]*image_texture_lookup(filename, color_space, Vector[0], Vector[2], tmp_alpha);
Color += weight[1]*image_texture_lookup(filename, color_space, p[0], p[2], tmp_alpha);
Alpha += weight[1]*tmp_alpha;
}
if (weight[2] > 0.0) {
Color += weight[2]*image_texture_lookup(filename, color_space, Vector[1], Vector[0], tmp_alpha);
Color += weight[2]*image_texture_lookup(filename, color_space, p[1], p[0], tmp_alpha);
Alpha += weight[2]*tmp_alpha;
}
}

@ -93,12 +93,19 @@ color magic(point p, int n, float distortion)
}
shader node_magic_texture(
int use_mapping = 0,
matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
int Depth = 2,
float Distortion = 5.0,
float Scale = 5.0,
point Vector = P,
output color Color = color(0.0, 0.0, 0.0))
{
Color = magic(Vector * Scale, Depth, Distortion);
point p = Vector;
if (use_mapping)
p = transform(mapping, p);
Color = magic(p * Scale, Depth, Distortion);
}

@ -187,6 +187,8 @@ float noise_musgrave_ridged_multi_fractal(point p, string basis, float H,
/* Shader */
shader node_musgrave_texture(
int use_mapping = 0,
matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
string Type = "fBM",
float Dimension = 2.0,
float Lacunarity = 1.0,
@ -204,7 +206,12 @@ shader node_musgrave_texture(
string Basis = "Perlin";
float intensity = 1.0;
point p = Vector * Scale;
point p = Vector;
if (use_mapping)
p = transform(mapping, p);
p = p * Scale;
if (Type == "Multifractal")
Fac = intensity * noise_musgrave_multi_fractal(p, Basis, dimension, lacunarity, octaves);

@ -43,6 +43,8 @@ float noise(point p, string basis, float distortion, float detail, float fac, co
}
shader node_noise_texture(
int use_mapping = 0,
matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
float Distortion = 0.0,
float Scale = 5.0,
float Detail = 2.0,
@ -50,7 +52,12 @@ shader node_noise_texture(
output float Fac = 0.0,
output color Color = color(0.2, 0.2, 0.2))
{
point p = Vector;
if (use_mapping)
p = transform(mapping, p);
string Basis = "Perlin";
Fac = noise(Vector * Scale, Basis, Distortion, Detail, Fac, Color);
Fac = noise(p * Scale, Basis, Distortion, Detail, Fac, Color);
}

@ -149,14 +149,21 @@ void precompute_sunsky(vector dir, float turbidity, output KernelSunSky sunsky)
}
shader node_sky_texture(
int use_mapping = 0,
matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
vector Vector = P,
vector sun_direction = vector(0, 0, 1),
float turbidity = 2.2,
output color Color = color(0.0, 0.0, 0.0))
{
vector p = Vector;
if (use_mapping)
p = transform(mapping, p);
KernelSunSky sunsky;
precompute_sunsky(sun_direction, turbidity, sunsky);
Color = sky_xyz_radiance(sunsky, Vector);
Color = sky_xyz_radiance(sunsky, p);
}

@ -22,17 +22,24 @@
/* Voronoi */
shader node_voronoi_texture(
int use_mapping = 0,
matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
string Coloring = "Intensity",
float Scale = 5.0,
point Vector = P,
output float Fac = 0.0,
output color Color = color(0.0, 0.0, 0.0))
{
point p = Vector;
if (use_mapping)
p = transform(mapping, p);
/* compute distance and point coordinate of 4 nearest neighbours */
float da[4];
point pa[4];
voronoi(Vector * Scale, "Distance Squared", 1.0, da, pa);
voronoi(p * Scale, "Distance Squared", 1.0, da, pa);
/* Colored output */
if (Coloring == "Intensity") {

@ -46,6 +46,8 @@ float wave(point p, float scale, string type, float detail, float distortion, fl
}
shader node_wave_texture(
int use_mapping = 0,
matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
string Type = "Bands",
float Scale = 5.0,
float Distortion = 0.0,
@ -55,7 +57,12 @@ shader node_wave_texture(
output float Fac = 0.0,
output color Color = color (0.0, 0.0, 0.0))
{
Fac = wave(Vector, Scale, Type, Detail, Distortion, DetailScale);
point p = Vector;
if (use_mapping)
p = transform(mapping, p);
Fac = wave(p, Scale, Type, Detail, Distortion, DetailScale);
Color = color(Fac, Fac, Fac);
}

@ -67,7 +67,7 @@ void ImageManager::set_extended_image_limits(void)
tex_image_byte_start = TEX_EXTENDED_IMAGE_BYTE_START;
}
static bool is_float_image(const string& filename)
bool ImageManager::is_float_image(const string& filename)
{
ImageInput *in = ImageInput::create(filename);
bool is_float = false;

@ -53,6 +53,7 @@ public:
int add_image(const string& filename, bool& is_float);
void remove_image(const string& filename);
bool is_float_image(const string& filename);
void device_update(Device *device, DeviceScene *dscene, Progress& progress);
void device_free(Device *device, DeviceScene *dscene);

@ -100,6 +100,16 @@ void TextureMapping::compile(SVMCompiler& compiler, int offset_in, int offset_ou
}
}
void TextureMapping::compile(OSLCompiler &compiler)
{
if(!skip()) {
Transform tfm = transform_transpose(compute_transform());
compiler.parameter("mapping", tfm);
compiler.parameter("use_mapping", 1);
}
}
/* Image Texture */
static ShaderEnum color_space_init()
@ -130,7 +140,7 @@ ImageTextureNode::ImageTextureNode()
{
image_manager = NULL;
slot = -1;
is_float = false;
is_float = -1;
filename = "";
color_space = ustring("Color");
projection = ustring("Flat");;
@ -152,7 +162,7 @@ ShaderNode *ImageTextureNode::clone() const
ImageTextureNode *node = new ImageTextureNode(*this);
node->image_manager = NULL;
node->slot = -1;
node->is_float = false;
node->is_float = -1;
return node;
}
@ -163,8 +173,11 @@ void ImageTextureNode::compile(SVMCompiler& compiler)
ShaderOutput *alpha_out = output("Alpha");
image_manager = compiler.image_manager;
if(slot == -1)
slot = image_manager->add_image(filename, is_float);
if(is_float == -1) {
bool is_float_bool;
slot = image_manager->add_image(filename, is_float_bool);
is_float = (int)is_float_bool;
}
if(!color_out->links.empty())
compiler.stack_assign(color_out);
@ -220,6 +233,11 @@ void ImageTextureNode::compile(SVMCompiler& compiler)
void ImageTextureNode::compile(OSLCompiler& compiler)
{
tex_mapping.compile(compiler);
if(is_float == -1)
is_float = (int)image_manager->is_float_image(filename);
compiler.parameter("filename", filename.c_str());
if(is_float || color_space != "Color")
compiler.parameter("color_space", "Linear");
@ -250,7 +268,7 @@ EnvironmentTextureNode::EnvironmentTextureNode()
{
image_manager = NULL;
slot = -1;
is_float = false;
is_float = -1;
filename = "";
color_space = ustring("Color");
projection = ustring("Equirectangular");
@ -271,7 +289,7 @@ ShaderNode *EnvironmentTextureNode::clone() const
EnvironmentTextureNode *node = new EnvironmentTextureNode(*this);
node->image_manager = NULL;
node->slot = -1;
node->is_float = false;
node->is_float = -1;
return node;
}
@ -282,8 +300,11 @@ void EnvironmentTextureNode::compile(SVMCompiler& compiler)
ShaderOutput *alpha_out = output("Alpha");
image_manager = compiler.image_manager;
if(slot == -1)
slot = image_manager->add_image(filename, is_float);
if(slot == -1) {
bool is_float_bool;
slot = image_manager->add_image(filename, is_float_bool);
is_float = (int)is_float_bool;
}
if(!color_out->links.empty())
compiler.stack_assign(color_out);
@ -328,6 +349,11 @@ void EnvironmentTextureNode::compile(SVMCompiler& compiler)
void EnvironmentTextureNode::compile(OSLCompiler& compiler)
{
tex_mapping.compile(compiler);
if(is_float == -1)
is_float = (int)image_manager->is_float_image(filename);
compiler.parameter("filename", filename.c_str());
compiler.parameter("projection", projection);
if(is_float || color_space != "Color")
@ -439,6 +465,8 @@ void SkyTextureNode::compile(SVMCompiler& compiler)
void SkyTextureNode::compile(OSLCompiler& compiler)
{
tex_mapping.compile(compiler);
compiler.parameter_vector("sun_direction", sun_direction);
compiler.parameter("turbidity", turbidity);
compiler.add(this, "node_sky_texture");
@ -502,6 +530,8 @@ void GradientTextureNode::compile(SVMCompiler& compiler)
void GradientTextureNode::compile(OSLCompiler& compiler)
{
tex_mapping.compile(compiler);
compiler.parameter("Type", type);
compiler.add(this, "node_gradient_texture");
}
@ -560,6 +590,8 @@ void NoiseTextureNode::compile(SVMCompiler& compiler)
void NoiseTextureNode::compile(OSLCompiler& compiler)
{
tex_mapping.compile(compiler);
compiler.add(this, "node_noise_texture");
}
@ -620,6 +652,8 @@ void VoronoiTextureNode::compile(SVMCompiler& compiler)
void VoronoiTextureNode::compile(OSLCompiler& compiler)
{
tex_mapping.compile(compiler);
compiler.parameter("Coloring", coloring);
compiler.add(this, "node_voronoi_texture");
}
@ -707,6 +741,8 @@ void MusgraveTextureNode::compile(SVMCompiler& compiler)
void MusgraveTextureNode::compile(OSLCompiler& compiler)
{
tex_mapping.compile(compiler);
compiler.parameter("Type", type);
compiler.add(this, "node_musgrave_texture");
@ -785,6 +821,8 @@ void WaveTextureNode::compile(SVMCompiler& compiler)
void WaveTextureNode::compile(OSLCompiler& compiler)
{
tex_mapping.compile(compiler);
compiler.parameter("Type", type);
compiler.add(this, "node_wave_texture");
@ -842,6 +880,8 @@ void MagicTextureNode::compile(SVMCompiler& compiler)
void MagicTextureNode::compile(OSLCompiler& compiler)
{
tex_mapping.compile(compiler);
compiler.parameter("Depth", depth);
compiler.add(this, "node_magic_texture");
}
@ -898,6 +938,8 @@ void CheckerTextureNode::compile(SVMCompiler& compiler)
void CheckerTextureNode::compile(OSLCompiler& compiler)
{
tex_mapping.compile(compiler);
compiler.add(this, "node_checker_texture");
}
@ -986,6 +1028,8 @@ void BrickTextureNode::compile(SVMCompiler& compiler)
void BrickTextureNode::compile(OSLCompiler& compiler)
{
tex_mapping.compile(compiler);
compiler.parameter("Offset", offset);
compiler.parameter("OffsetFrequency", offset_frequency);
compiler.parameter("Squash", squash);

@ -36,6 +36,7 @@ public:
Transform compute_transform();
bool skip();
void compile(SVMCompiler& compiler, int offset_in, int offset_out);
void compile(OSLCompiler &compiler);
float3 translation;
float3 rotation;
@ -67,7 +68,7 @@ public:
ImageManager *image_manager;
int slot;
bool is_float;
int is_float;
string filename;
ustring color_space;
ustring projection;
@ -85,7 +86,7 @@ public:
ImageManager *image_manager;
int slot;
bool is_float;
int is_float;
string filename;
ustring color_space;
ustring projection;

@ -81,7 +81,7 @@ void OSLShaderManager::device_update(Device *device, DeviceScene *dscene, Scene
if(shader->sample_as_light && shader->has_surface_emission)
scene->light_manager->need_update = true;
OSLCompiler compiler((void*)this, (void*)ss);
OSLCompiler compiler((void*)this, (void*)ss, scene->image_manager);
compiler.background = (shader == scene->shaders[scene->default_background]);
compiler.compile(og, shader);
}
@ -286,10 +286,11 @@ const char *OSLShaderManager::shader_load_bytecode(const string& hash, const str
/* Graph Compiler */
OSLCompiler::OSLCompiler(void *manager_, void *shadingsys_)
OSLCompiler::OSLCompiler(void *manager_, void *shadingsys_, ImageManager *image_manager_)
{
manager = manager_;
shadingsys = shadingsys_;
image_manager = image_manager_;
current_type = SHADER_TYPE_SURFACE;
current_shader = NULL;
background = false;

@ -83,7 +83,7 @@ protected:
class OSLCompiler {
public:
OSLCompiler(void *manager, void *shadingsys);
OSLCompiler(void *manager, void *shadingsys, ImageManager *image_manager);
void compile(OSLGlobals *og, Shader *shader);
void add(ShaderNode *node, const char *name, bool isfilepath = false);
@ -110,6 +110,7 @@ public:
ShaderType output_type() { return current_type; }
bool background;
ImageManager *image_manager;
private:
string id(ShaderNode *node);