Fix for blender_stucci ( + implicit wood fix )

Use this forum for general user support and related questions.
Forum rules
Please upload a testscene that allows developers to reproduce the problem, and attach some images.
Post Reply
jensverwiebe
Supporting Users
Posts: 141
Joined: Tue Jan 09, 2018 6:48 pm

Fix for blender_stucci ( + implicit wood fix )

Post by jensverwiebe »

Blender stucci was completely broken.
Here is a fix for the right parsing + a fixed conditional of the ptypes.
This also fixes partly blender_wood behavior.

Edit:fixed overdone part.

Ingredients:

Code: Select all

diff --git a/src/slg/scene/parsetextures.cpp b/src/slg/scene/parsetextures.cpp
index c5c8f91..bedd285 100644
--- a/src/slg/scene/parsetextures.cpp
+++ b/src/slg/scene/parsetextures.cpp
@@ -269,7 +269,7 @@ Texture *Scene::CreateTexture(const string &texName, const Properties &props) {
 
 		tex = new BlenderNoiseTexture(noisedepth, bright, contrast);
 	} else if (texType == "blender_stucci") {
-		const string woodtype = props.Get(Property(propName + ".stuccitype")("plastic")).Get<string>();
+		const string stuccitype = props.Get(Property(propName + ".stuccitype")("plastic")).Get<string>();
 		const string noisebasis = props.Get(Property(propName + ".noisebasis")("blender_original")).Get<string>();
 		const string hard = props.Get(Property(propName + ".noisetype")("soft_noise")).Get<string>();
 		const float noisesize = props.Get(Property(propName + ".noisesize")(.25f)).Get<float>();
@@ -278,7 +278,7 @@ Texture *Scene::CreateTexture(const string &texName, const Properties &props) {
 		const float contrast = props.Get(Property(propName + ".contrast")(1.f)).Get<float>();
 
 		tex = new BlenderStucciTexture(CreateTextureMapping3D(propName + ".mapping", props),
-				woodtype, noisebasis, noisesize, turbulence, (hard=="hard_noise"), bright, contrast);
+				stuccitype, noisebasis, noisesize, turbulence, (hard=="hard_noise"), bright, contrast);
 	} else if (texType == "blender_wood") {
 		const string woodtype = props.Get(Property(propName + ".woodtype")("bands")).Get<string>();
 		const string noisebasis = props.Get(Property(propName + ".noisebasis")("blender_original")).Get<string>();

Last edited by jensverwiebe on Mon Feb 19, 2018 2:13 pm, edited 2 times in total.
User avatar
Dade
Developer
Developer
Posts: 5672
Joined: Mon Dec 04, 2017 8:36 pm
Location: Italy

Re: Fix for blender_stucci ( + implicit wood fix )

Post by Dade »

This is the original Blender code:

Code: Select all

static int stucci(Tex *tex, const float texvec[3], TexResult *texres)
{
        float nor[3], b2, ofs;
        int retval= TEX_INT;
        
        b2= BLI_gNoise(tex->noisesize, texvec[0], texvec[1], texvec[2], (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis);
        
        ofs= tex->turbul/200.0f;

        if (tex->stype) ofs*=(b2*b2);
        nor[0] = BLI_gNoise(tex->noisesize, texvec[0]+ofs, texvec[1], texvec[2], (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis);
        nor[1] = BLI_gNoise(tex->noisesize, texvec[0], texvec[1]+ofs, texvec[2], (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis);
        nor[2] = BLI_gNoise(tex->noisesize, texvec[0], texvec[1], texvec[2]+ofs, (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis);

        texres->tin= nor[2];
        
        if (texres->nor) {
                
                copy_v3_v3(texres->nor, nor);
                tex_normal_derivate(tex, texres);
                
                if (tex->stype==TEX_WALLOUT) {
                        texres->nor[0]= -texres->nor[0];
                        texres->nor[1]= -texres->nor[1];
                        texres->nor[2]= -texres->nor[2];
                }
                
                retval |= TEX_NOR;
        }
        
        if (tex->stype==TEX_WALLOUT)
                texres->tin= 1.0f-texres->tin;
        
        if (texres->tin<0.0f)
                texres->tin= 0.0f;
        
        return retval;
}
As far as I can see, the LuxCore code is a correct port of Blender code.

Your patch rename a variable in the first part. And return always 0.0 for "type==TEX_PLASTIC" ("nor[2] = BLI_gNoise(noisesize, P.x, P.y, P.z + ofs, hard, noisebasis)" is evaluate only for "type != TEX_PLASTIC"), it is not correct.
Support LuxCoreRender project with salts and bounties
jensverwiebe
Supporting Users
Posts: 141
Joined: Tue Jan 09, 2018 6:48 pm

Re: Fix for blender_stucci ( + implicit wood fix )

Post by jensverwiebe »

Ic, leave that part out ( blender_texture.cpp )
The first part was definitely cp/paste issue to fix ( readability ). blender_stucci has by no means a woodtype.

Code: Select all

diff --git a/src/slg/scene/parsetextures.cpp b/src/slg/scene/parsetextures.cpp
index c5c8f91..bedd285 100644
--- a/src/slg/scene/parsetextures.cpp
+++ b/src/slg/scene/parsetextures.cpp
@@ -269,7 +269,7 @@ Texture *Scene::CreateTexture(const string &texName, const Properties &props) {
 
 		tex = new BlenderNoiseTexture(noisedepth, bright, contrast);
 	} else if (texType == "blender_stucci") {
-		const string woodtype = props.Get(Property(propName + ".stuccitype")("plastic")).Get<string>();
+		const string stuccitype = props.Get(Property(propName + ".stuccitype")("plastic")).Get<string>();
 		const string noisebasis = props.Get(Property(propName + ".noisebasis")("blender_original")).Get<string>();
 		const string hard = props.Get(Property(propName + ".noisetype")("soft_noise")).Get<string>();
 		const float noisesize = props.Get(Property(propName + ".noisesize")(.25f)).Get<float>();
@@ -278,7 +278,7 @@ Texture *Scene::CreateTexture(const string &texName, const Properties &props) {
 		const float contrast = props.Get(Property(propName + ".contrast")(1.f)).Get<float>();
 
 		tex = new BlenderStucciTexture(CreateTextureMapping3D(propName + ".mapping", props),
-				woodtype, noisebasis, noisesize, turbulence, (hard=="hard_noise"), bright, contrast);
+				stuccitype, noisebasis, noisesize, turbulence, (hard=="hard_noise"), bright, contrast);
 	} else if (texType == "blender_wood") {
 		const string woodtype = props.Get(Property(propName + ".woodtype")("bands")).Get<string>();
 		const string noisebasis = props.Get(Property(propName + ".noisebasis")("blender_original")).Get<string>();
Know now where the confusion comes from:
ring = ringnoise aka band = bandnoise if turbulence == 0, noisesize has no effect logically then.
In blender thats simplified now ( and renamed to wave texture )

@Simon aka B.Y.O.B.
This could be a simplification for exporter:
Have only ring and band type but export as ringnoise respectively bandnoise if turbulence != 0

EDIT: without working on blender_texture.cpp stucci, plastic looks exact same as wall_in, that cannot be right.
EDIT2: 'am back to my first patch, looks better. Images asap. Perhaps the normals thingie is not 100% yet.

Left to right: plastic - wall_in - wall_out / added local mapping, better to compare )
orig:
orig__stucci.png
mine:
my__stucci.png
mine bump only, tbh, cannot see any wrong outcome ( plastic is kinda softer wall_in, that looks right ):
my_stucci_bump_only.png
Think from here we can discuss now ?
Blenders own implementation is also very slight, but nothing speaks against doing it better imho.
Last edited by jensverwiebe on Mon Feb 19, 2018 9:08 pm, edited 1 time in total.
User avatar
B.Y.O.B.
Developer
Developer
Posts: 4146
Joined: Mon Dec 04, 2017 10:08 pm
Location: Germany
Contact:

Re: Fix for blender_stucci ( + implicit wood fix )

Post by B.Y.O.B. »

jensverwiebe wrote: Mon Feb 19, 2018 2:08 pm @Simon aka B.Y.O.B.
This could be a simplification for exporter:
Have only ring and band type but export as ringnoise respectively bandnoise if turbulence != 0
You can create an issue or fork the repo, implement it and send a pull request.
But I currently have other priorities to be honest.
Post Reply