Blender noise texture gives vertical stripe patterns #42139

Closed
opened 2014-10-08 00:10:31 +02:00 by Daniel Salazar · 25 comments
Member

System Information

openSUSE 12.3 64bits
NVIDIA 480GTX SC
AMD FX-8350

Blender Version
Broken: a8705e9

Short description of error

Strange vertical stripe patterns coming from the noise texture

Exact steps for others to reproduce the error

Render this: noise.blend

**System Information** openSUSE 12.3 64bits NVIDIA 480GTX SC AMD FX-8350 **Blender Version** Broken: a8705e9 **Short description of error** Strange vertical stripe patterns coming from the noise texture **Exact steps for others to reproduce the error** Render this: [noise.blend](https://archive.blender.org/developer/F115422/noise.blend)
Author
Member

Changed status to: 'Open'

Changed status to: 'Open'
Author
Member

Added subscriber: @zanqdo

Added subscriber: @zanqdo
Daniel Salazar changed title from Blender noise texture gives vertical tripe patterns to Blender noise texture gives vertical stripe patterns 2014-10-08 00:11:06 +02:00

Added subscriber: @willi-2

Added subscriber: @willi-2

Yep, reproducable here on Win7/64, Blender 2.72. Problem seems to be there "forever", i.e. tried back to first 2.5 release. Don't know if it's a bug as I've never used a noise texture in the compositer yet.

It's noticable that the preview of the texture in the texture property section, if enlarged, doesn't show this behavior.

Yep, reproducable here on Win7/64, Blender 2.72. Problem seems to be there "forever", i.e. tried back to first 2.5 release. Don't know if it's a bug as I've never used a noise texture in the compositer yet. It's noticable that the preview of the texture in the texture property section, if enlarged, doesn't show this behavior.

Added subscriber: @AditiaA.Pratama

Added subscriber: @AditiaA.Pratama

yes, confirmed here too. Ubuntu 14.04 64bit, blender 2.72 47b8bf5

yes, confirmed here too. Ubuntu 14.04 64bit, blender 2.72 47b8bf5

Added subscriber: @AnthonyEdlin

Added subscriber: @AnthonyEdlin

Well, looks like the problem may be in the texnoise function of the render_texture.c file. This is from a commit by Ton in 2003. Here it is:

static int texnoise(Tex *tex, TexResult *texres)
{
	float div=3.0;
	int val, ran, loop;
	
	ran= BLI_rand();
	val= (ran & 3);
	
	loop= tex->noisedepth;
	while (loop--) {
		ran= (ran>>2);
		val*= (ran & 3);
		div*= 3.0f;
	}
	
	texres->tin= ((float)val)/div;

	BRICONT;
	return TEX_INT;
}

If you change texres->tin line to:

	texres->tin= BLI_frand();

Then you get actual noise and the lines go away.

As far as the part above with the loop, I don't really know why it was done like that. The noisedepth variable is always 2, as far as I can tell. Which means you only have a few values possible (0-3 * 0-3 * 0-3)/27, and a higher chance of getting darker values and pure black (1 in 4 chance I think), which you can see easily in the image produced by the noise. I can't think of why this part would make the lines, but I haven't dug into it more then this either.

Well, looks like the problem may be in the texnoise function of the render_texture.c file. This is from a commit by Ton in 2003. Here it is: ``` static int texnoise(Tex *tex, TexResult *texres) { float div=3.0; int val, ran, loop; ran= BLI_rand(); val= (ran & 3); loop= tex->noisedepth; while (loop--) { ran= (ran>>2); val*= (ran & 3); div*= 3.0f; } texres->tin= ((float)val)/div; BRICONT; return TEX_INT; } ``` If you change texres->tin line to: ``` texres->tin= BLI_frand(); ``` Then you get actual noise and the lines go away. As far as the part above with the loop, I don't really know why it was done like that. The noisedepth variable is always 2, as far as I can tell. Which means you only have a few values possible (0-3 * 0-3 * 0-3)/27, and a higher chance of getting darker values and pure black (1 in 4 chance I think), which you can see easily in the image produced by the noise. I can't think of why this part would make the lines, but I haven't dug into it more then this either.
Lukas Tönne self-assigned this 2014-10-08 11:20:57 +02:00

To add a little more info, the lines only show up with certain render size X resolutions. At 1024 you get vertical lines, at 1023 you get diagonal lines, and at 1022 you get even more slanted lines. At a size of about 1000 I can't really see the lines anymore. At 512 and 2048 the lines show up again, with the same pattern of going away if you increment/decrement by 1 repeatedly.

To add a little more info, the lines only show up with certain render size X resolutions. At 1024 you get vertical lines, at 1023 you get diagonal lines, and at 1022 you get even more slanted lines. At a size of about 1000 I can't really see the lines anymore. At 512 and 2048 the lines show up again, with the same pattern of going away if you increment/decrement by 1 repeatedly.
Member

Added subscriber: @Ton

Added subscriber: @Ton
Member

The idea was to get noise with control over the noise "depth". It was to simulate a primitive sort of grain or digital camera noise.

Why this pattern happens i dunno, but the solution (replace with frand) is of course not a solution.
There might have been an optimization in our rand code? I don't think we had BLI_rand in 2003.

The idea was to get noise with control over the noise "depth". It was to simulate a primitive sort of grain or digital camera noise. Why this pattern happens i dunno, but the solution (replace with frand) is of course not a solution. There might have been an optimization in our rand code? I don't think we had BLI_rand in 2003.
Member

Checked - we did have BLI_rand() - no time to further investigate what happened there.

Checked - we did have BLI_rand() - no time to further investigate what happened there.
Member

I have a feeling this problem is due to the use of the global random number generator (RNG) in the noise function. This is succeptible to re-seeding in other parts of the code. In this case i suspect the compositor or some other part of the code resets the RNG for each tile, line etc. This could lead to repetitive values in the noise function and give the stripe pattern. Another potential cause could be threading: the original RNG seed is a static variable, which starts at the same value for each compositor thread or so.

See this comparison of compositor noise with rendered noise - no stripes in render output using the same function: noise2.blend

Ideally random numbers in textures should use per-thread RNGs for consistency - but making this reliable and repeatable is not so easy, not least due to legacy design issues (no real texture instances for BI materials and other tex users). Might be best to file this under "todo" and recommend reliable cloud patterns etc instead, but will see if fiddling with random seed in the compositor helps.

I have a feeling this problem is due to the use of the global random number generator (RNG) in the noise function. This is succeptible to re-seeding in other parts of the code. In this case i suspect the compositor or some other part of the code resets the RNG for each tile, line etc. This could lead to repetitive values in the noise function and give the stripe pattern. Another potential cause could be threading: the original RNG seed is a static variable, which starts at the same value for each compositor thread or so. See this comparison of compositor noise with rendered noise - no stripes in render output using the same function: [noise2.blend](https://archive.blender.org/developer/F115463/noise2.blend) Ideally random numbers in textures should use per-thread RNGs for consistency - but making this reliable and repeatable is not so easy, not least due to legacy design issues (no real texture instances for BI materials and other tex users). Might be best to file this under "todo" and recommend reliable cloud patterns etc instead, but will see if fiddling with random seed in the compositor helps.

This issue was referenced by 016e75ad64

This issue was referenced by 016e75ad64935775b487e6674f7c2a4f084cd7fe

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'

Closed by commit 016e75ad64.

Closed by commit 016e75ad64.
Author
Member

Thanks @Psy-Fi I owe you another beer gawd dammit!

Thanks @Psy-Fi I owe you another beer gawd dammit!

Hi psy-fi,

I'm a little confused about some parts of this commit for a couple of reasons.

First, the reason I suggested just using frand was that it gave the full value of the random number and it also provided even distribution of the values. Of course one of the problems with this is that it breaks old files. Meaning someone may have setup nodes or combinations of textures that expect the old formula and now when they open their file they get a different value weight of noise.

Your commit also significantly changes the value weight of the noise. In this case it's not even distribution like using the full random value or with a strong black weight like the old formula, but instead weights the values to grey, which you can see easily in the histogram. So this leaves me with questions. Was it not possible to just use the upper bits and the new random thread functionality but with the old formula so it didn't change old files? If it was intended to change the formula, why did you choose one that weights grey?

The second issue is just an implementation problem. In your commit you start the loop by getting the 31st and 32nd bits in the random number, but if you look in the random code implementation and comments you see that it only provides 31 bits. The 32nd bit is masked off I assume so that you always get positive numbers on signed ints. This gives a strange set of possible values ((0 to 7)/9) with your current formula, which you can see in this histogram.

HistogramIncorrect.png

To fix this just set shift to 29 instead of 30. This gives ((0 to 9)/9), which I think is what you intended and gives a histogram like this.

HistogramCorrect.png

Hi psy-fi, I'm a little confused about some parts of this commit for a couple of reasons. First, the reason I suggested just using frand was that it gave the full value of the random number and it also provided even distribution of the values. Of course one of the problems with this is that it breaks old files. Meaning someone may have setup nodes or combinations of textures that expect the old formula and now when they open their file they get a different value weight of noise. Your commit also significantly changes the value weight of the noise. In this case it's not even distribution like using the full random value or with a strong black weight like the old formula, but instead weights the values to grey, which you can see easily in the histogram. So this leaves me with questions. Was it not possible to just use the upper bits and the new random thread functionality but with the old formula so it didn't change old files? If it was intended to change the formula, why did you choose one that weights grey? The second issue is just an implementation problem. In your commit you start the loop by getting the 31st and 32nd bits in the random number, but if you look in the random code implementation and comments you see that it only provides 31 bits. The 32nd bit is masked off I assume so that you always get positive numbers on signed ints. This gives a strange set of possible values ((0 to 7)/9) with your current formula, which you can see in this histogram. ![HistogramIncorrect.png](https://archive.blender.org/developer/F116813/HistogramIncorrect.png) To fix this just set shift to 29 instead of 30. This gives ((0 to 9)/9), which I think is what you intended and gives a histogram like this. ![HistogramCorrect.png](https://archive.blender.org/developer/F116824/HistogramCorrect.png)
Member

Changed status from 'Resolved' to: 'Open'

Changed status from 'Resolved' to: 'Open'
Member

Added subscriber: @Psy-Fi

Added subscriber: @Psy-Fi
Member

Yes, the old implementation may not be ideal, but changing the visual result should be avoided if possible. Reopening for investigation and assigning to @psy-fi.

Yes, the old implementation may not be ideal, but changing the visual result should be avoided if possible. Reopening for investigation and assigning to @psy-fi.
Lukas Tönne removed their assignment 2014-10-15 09:41:12 +02:00
Antonis Ryakiotakis was assigned by Lukas Tönne 2014-10-15 09:41:12 +02:00
Member

Added subscriber: @LukasTonne

Added subscriber: @LukasTonne

Thanks, I hadn't noticed that random used 31 bits, I'll recheck and also reuse the old multiplication formula to keep the old look if possible.

Thanks, I hadn't noticed that random used 31 bits, I'll recheck and also reuse the old multiplication formula to keep the old look if possible.

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'

Fixed, thanks for doing the hard work here :)

Fixed, thanks for doing the hard work here :)
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
8 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#42139
No description provided.