[Bf-committers] More Woody Goody
Johnny Matthews
johnny.matthews at gmail.com
Wed Mar 2 15:28:10 CET 2005
Hey Chris,
Tried your patch and am getting an unresolved external on rint in
wood_tri on MS Command line tools with scons. Where is this supposed to
come from?
Johnny
Chris Burt wrote:
> Here is another update to the wood patch. This has an improved formula
> for creating a triangle wave. No more long-winded Fourier series, just
> a simple fabs and rint which seems to be quite effective. Made some
> changes to the code at Ton's suggestion. Still open for review! Oh and
> those screenshots are coming!
>
> --Regards,
> --Chris Burt
>
> Chris Burt wrote:
>
>> Hi all, this is an upgrade to the wood patch which maintains
>> backwards compatibility (so far as I know) and also features an
>> improvement:
>>
>> The Wood Texture panel now offers a "Sin" "Tri" and "Saw" waveform
>> button, allowing the user to select which waveform they wish to use.
>> Results vary quite a lot from option to option. I'll make screen
>> shots tomorrow. I think this patch is actually quite nice and I've
>> tidied up the wood texture code a little bit, adding defines where
>> magic numbers existed before. Its now a bit more readable and the
>> functions which determine the intensity of the wood are now three
>> separate calls wood_sin (original), wood_saw and wood_tri (both new).
>> So more information and screenshots tomorrow for those interested.
>> This still needs testing etc, but my from my experiments its quite
>> fun. Here's one small sample already:
>>
>> http://blender.spaceisbig.com/wood_or_steel.png
>>
>> Looks a little like diamond plate I thought. Its two wood texture
>> criss-crossing.
>>
>> Anyway.. late now! Patch is attached. Thanks!
>>
>> Regards,
>> --Chris Burt
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Bf-committers mailing list
>> Bf-committers at projects.blender.org
>> http://projects.blender.org/mailman/listinfo/bf-committers
>
>------------------------------------------------------------------------
>
>Index: source/blender/render/intern/source/texture.c
>===================================================================
>RCS file: /cvsroot/bf-blender/blender/source/blender/render/intern/source/texture.c,v
>retrieving revision 1.38
>diff -u -p -u -r1.38 texture.c
>--- source/blender/render/intern/source/texture.c 25 Feb 2005 12:19:42 -0000 1.38
>+++ source/blender/render/intern/source/texture.c 2 Mar 2005 12:57:58 -0000
>@@ -354,30 +354,71 @@ static int clouds(Tex *tex, float *texve
>
> }
>
>+/* creates a sine wave */
>+static float wood_sin(float a)
>+{
>+ a = 0.5 + 0.5*sin(a);
>+
>+ return a;
>+}
>+
>+/* creates a saw wave */
>+static float wood_saw(float a)
>+{
>+ const float b = 2*M_PI;
>+
>+ int n = (int)(a / b);
>+ a -= n*b;
>+ if (a < 0) a += b;
>+ return a / b;
>+}
>+
>+/* creates a triangle wave */
>+static float wood_tri(float a)
>+{
>+ const float b = 2*M_PI;
>+ const float rmax = 1.0;
>+
>+ a = rmax - 2.0*fabs(rint(a*(1.0/b)) - (a*(1.0/b)));
>+
>+ return a;
>+}
>+
> /* computes basic wood intensity value at x,y,z */
> static float wood_int(Tex *tex, float x, float y, float z)
> {
>- float wi=0;
>+ float wi=0;
>+ short wf = tex->noisebasis2; /* wave form: TEX_SIN=0, TEX_SAW=1, TEX_TRI=2 */
>+ short wt = tex->stype; /* wood type: TEX_BAND=0, TEX_RING=1, TEX_BANDNOISE=2, TEX_RINGNOISE=3 */
>
>- if (tex->stype==0)
>- wi = 0.5 + 0.5*sin((x + y + z)*10.0);
>- else if (tex->stype==1)
>- wi = 0.5 + 0.5*sin(sqrt(x*x + y*y + z*z)*20.0);
>- else if (tex->stype==2) {
>- wi = BLI_gNoise(tex->noisesize, x, y, z, (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis);
>- wi = 0.5 + 0.5*sin(tex->turbul*wi + (x + y + z)*10.0);
>+ float (*waveform[3])(float); /* create array of pointers to waveform functions */
>+ waveform[0] = wood_sin; /* assign address of wood_sin() function to pointer array */
>+ waveform[1] = wood_saw;
>+ waveform[2] = wood_tri;
>+
>+ if ((wf>TEX_TRI) || (wf<TEX_SIN)) wf=0; /* check to be sure noisebasis2 is initialized ahead of time */
>+
>+ if (wt==TEX_BAND) {
>+ wi = waveform[wf]((x + y + z)*10.0);
> }
>- else if (tex->stype==3) {
>- wi = BLI_gNoise(tex->noisesize, x, y, z, (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis);
>- wi = 0.5 + 0.5*sin(tex->turbul*wi + (sqrt(x*x + y*y + z*z))*20.0);
>+ else if (wt==TEX_RING) {
>+ wi = waveform[wf](sqrt(x*x + y*y + z*z)*20.0);
> }
>-
>+ else if (wt==TEX_BANDNOISE) {
>+ wi = tex->turbul*BLI_gNoise(tex->noisesize, x, y, z, (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis);
>+ wi = waveform[wf]((x + y + z)*10.0 + wi);
>+ }
>+ else if (wt==TEX_RINGNOISE) {
>+ wi = tex->turbul*BLI_gNoise(tex->noisesize, x, y, z, (tex->noisetype!=TEX_NOISESOFT), tex->noisebasis);
>+ wi = waveform[wf](sqrt(x*x + y*y + z*z)*20.0 + wi);
>+ }
>+
> return wi;
> }
>
> static int wood(Tex *tex, float *texvec, TexResult *texres)
> {
>- int rv=0; /* return value, int:0, col:1, nor:2, everything:3 */
>+ int rv=TEX_INT; /* return value, int:0, col:1, nor:2, everything:3 */
>
> texres->tin = wood_int(tex, texvec[0], texvec[1], texvec[2]);
> if (texres->nor!=NULL) {
>@@ -387,7 +428,7 @@ static int wood(Tex *tex, float *texvec,
> texres->nor[2] = wood_int(tex, texvec[0], texvec[1], texvec[2] + tex->nabla);
>
> tex_normal_derivate(tex, texres);
>- rv += 2;
>+ rv = TEX_NOR;
> }
>
> BRICONT;
>Index: source/blender/makesdna/DNA_texture_types.h
>===================================================================
>RCS file: /cvsroot/bf-blender/blender/source/blender/makesdna/DNA_texture_types.h,v
>retrieving revision 1.17
>diff -u -p -u -r1.17 DNA_texture_types.h
>--- source/blender/makesdna/DNA_texture_types.h 27 Dec 2004 19:28:49 -0000 1.17
>+++ source/blender/makesdna/DNA_texture_types.h 2 Mar 2005 12:57:58 -0000
>@@ -243,6 +243,16 @@ typedef struct Tex {
> #define TEX_NOISESOFT 0
> #define TEX_NOISEPERL 1
>
>+/* tex->noisebasis2 in texture.c - wood waveforms */
>+#define TEX_SIN 0
>+#define TEX_SAW 1
>+#define TEX_TRI 2
>+/* tex->stype in texture.c - wood types */
>+#define TEX_BAND 0
>+#define TEX_RING 1
>+#define TEX_BANDNOISE 2
>+#define TEX_RINGNOISE 3
>+
> /* wrap */
> #define MTEX_FLAT 0
> #define MTEX_CUBE 1
>Index: source/blender/src/buttons_shading.c
>===================================================================
>RCS file: /cvsroot/bf-blender/blender/source/blender/src/buttons_shading.c,v
>retrieving revision 1.120
>diff -u -p -u -r1.120 buttons_shading.c
>--- source/blender/src/buttons_shading.c 2 Feb 2005 17:26:24 -0000 1.120
>+++ source/blender/src/buttons_shading.c 2 Mar 2005 12:57:59 -0000
>@@ -882,10 +882,13 @@ static void texture_panel_wood(Tex *tex)
> uiDefButS(block, ROW, B_TEXPRV, "Bands", 10, 180, 75, 18, &tex->stype, 2.0, 0.0, 0, 0, "Uses standard wood texture in bands");
> uiDefButS(block, ROW, B_TEXPRV, "Rings", 85, 180, 75, 18, &tex->stype, 2.0, 1.0, 0, 0, "Uses wood texture in rings");
> uiDefButS(block, ROW, B_TEXPRV, "BandNoise", 160, 180, 75, 18, &tex->stype, 2.0, 2.0, 0, 0, "Adds noise to standard wood");
>- uiDefButS(block, ROW, B_TEXPRV, "RingNoise", 235, 180, 75, 18, &tex->stype, 2.0, 3.0, 0, 0, "Adds noise to rings");
>-
>- uiDefButS(block, ROW, B_TEXPRV, "Soft noise", 10, 160, 150, 19, &tex->noisetype, 12.0, 0.0, 0, 0, "Generates soft noise");
>- uiDefButS(block, ROW, B_TEXPRV, "Hard noise", 160, 160, 150, 19, &tex->noisetype, 12.0, 1.0, 0, 0, "Generates hard noise");
>+ uiDefButS(block, ROW, B_TEXPRV, "RingNoise", 235, 180, 75, 18, &tex->stype, 2.0, 3.0, 0, 0, "Adds noise to rings");
>+
>+ uiDefButS(block, ROW, B_TEXPRV, "Sin", 10, 160, 50, 19, &tex->noisebasis2, 8.0, 0.0, 0, 0, "Uses a sine wave to produce bands.");
>+ uiDefButS(block, ROW, B_TEXPRV, "Saw", 60, 160, 50, 19, &tex->noisebasis2, 8.0, 1.0, 0, 0, "Uses a saw wave to produce bands.");
>+ uiDefButS(block, ROW, B_TEXPRV, "Tri", 110, 160, 50, 19, &tex->noisebasis2, 8.0, 2.0, 0, 0, "Uses a triangle wave to produce bands.");
>+ uiDefButS(block, ROW, B_TEXPRV, "Soft noise", 160, 160, 75, 19, &tex->noisetype, 12.0, 0.0, 0, 0, "Generates soft noise");
>+ uiDefButS(block, ROW, B_TEXPRV, "Hard noise", 235, 160, 75, 19, &tex->noisetype, 12.0, 1.0, 0, 0, "Generates hard noise");
>
> uiBlockBeginAlign(block);
> uiDefButF(block, NUM, B_TEXPRV, "NoiseSize :", 10, 130, 150, 19, &tex->noisesize, 0.0001, 2.0, 10, 0, "Sets scaling for noise input");
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Bf-committers mailing list
>Bf-committers at projects.blender.org
>http://projects.blender.org/mailman/listinfo/bf-committers
>
>
More information about the Bf-committers
mailing list