Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SimplexNoise and NoiseTexture as new resources #21569

Merged
merged 1 commit into from
Sep 14, 2018

Conversation

JFonS
Copy link
Contributor

@JFonS JFonS commented Aug 29, 2018

SimplexNoise can be used to generate parameterized fractal noise based on Open Simplex, intended to be used in GDsrcipt.

NoiseTexture uses SimplexNoise to generate noise textures for using in
shaders/visual effects.

Documentation is missing, I will make a separate PR for that later on.

Edit: added option to use noise as a normalmap,

noise0
noise1

@Zylann
Copy link
Contributor

Zylann commented Aug 31, 2018

Should the class be named SimplexNoise even though the algorithm is actually OpenSimplex? (the name is still technically correct though)

@Megalomaniak
Copy link

Yes, I think SimplexNoise is better. A new user might not care for nor need to understand the difference so long as they are just familiar enough with noise types to know that it is a Perlin type noise function.

@Xrayez
Copy link
Contributor

Xrayez commented Sep 10, 2018

If the concern is the patent issue with simplex noise then based on my estimation it should expire on 2021 so we can be strategical about naming convention.. Besides, OpenSimplex implementation could be replaced with Simplex in the future.

extern "C" {
#endif

// -- GODOT start --
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are those changes needed? It should be documented (or ideally avoided if we can do without).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I saw the comment in the README.md. It would be nice to have a patch file like ./thirdparty/minizip/godot-zlib-1.2.4-minizip-seek.patch so that it can be easily reapplied when syncing with upstream.

##open-simplex-noise

- Upstream: https://github.com/smcameron/open-simplex-noise-in-c
- Version: git (0d555e7, 2018)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's 2015 :)

@@ -393,6 +393,23 @@ Files extracted from the upstream source:
- All .h files in `src/`
- LICENSE.txt

##open-simplex-noise
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a space after ##, and two lines between sections.

That being said, since it's only two files, I think it would be better to just put them in thirdparty/misc (and document them in the relevant section). You can likely drop the README and maybe name the license file open-simplex-noise-LICENSE.


- Upstream: https://github.com/smcameron/open-simplex-noise-in-c
- Version: git (0d555e7, 2018)
- License: The Unlicense
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The short identifier is just "Unlicense": https://spdx.org/licenses/Unlicense.html

@@ -0,0 +1,226 @@
#include "noise.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add Godot's copyright header.

I'd also suggest to rename noise.{cpp,h} to simplex_noise.{cpp,h} to match the class name.

@@ -0,0 +1,226 @@
#include "noise.h"
#include "core_string_names.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be core/core_string_names.h, I removed core/ from the include path. Please also add a line between noise.h (or simplex_noise.h) and other includes.

@@ -0,0 +1,62 @@
#ifndef OPENSIMPLEX_NOISE_H
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright header needed here too. The guard should likely be renamed to match the class and filename (so SIMPLEX_NOISE_H once renamed to simplex_noise.h).

#include "image.h"
#include "open-simplex-noise.h"
#include "scene/resources/texture.h"
#include <reference.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Godot headers are included with "", <> is for system/thirdparty headers. And core/ includes should be absolute. So this should be:

#include "core/image.h"
#include "core/reference.h"
#include "scene/resources/texture.h"

#include <open-simplex-noise.h>

@@ -0,0 +1,213 @@
#include "noise_texture.h"
#include "core_string_names.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, add core/ and a newline.

#include "editor/property_editor.h"
#include "image.h"
#include "noise.h"
#include <reference.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as in noise.h.

@JFonS JFonS force-pushed the add_noise_textures branch 3 times, most recently from f90d77a to 8ed68f5 Compare September 14, 2018 10:24
<argument index="1" name="height" type="int">
</argument>
<description>
Generate a noise image with the requested [code]width[\code] and [code]height[\code], based on the current noise parameters.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You got those slashes backwards :)

</argument>
<description>
Generate a tileable noise image, based on the current noise parameters.
Generated seamless images are always square ([code]size[\code]x[code]size[\code]).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too.


thirdparty_dir = '#thirdparty/misc/'
thirdparty_source = thirdparty_dir + 'open-simplex-noise.c'
env.Append(CPPPATH=thirdparty_dir)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's only one file, and not likely to be packaged by Linux distros and thus unbundled for the time being, I'd suggest not to include thirdparty/misc to the include path, and instead include thirdparty/misc/open-simplex-noise.h directly in the relevant files.

This saves us an extra 18 characters on every single compilation command line, which is nice to avoid logs growing to crazy sizes and Windows aborting the build due to too long instructions.

#include "core/reference.h"
#include "scene/resources/texture.h"

#include <open-simplex-noise.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do change it to thirdparty/misc/open-simplex-noise.h as I now suggested, it should go back to using double quotes as it's no longer a "system" include.

@JFonS JFonS force-pushed the add_noise_textures branch from 8ed68f5 to b5b1745 Compare September 14, 2018 13:17
SimplexNoise can be used to generate parameterized fractal noise based on Open Simplex.

NoiseTexture uses SimplexNoise to generate noise textures for using in
shaders/visual effects.
@JFonS JFonS force-pushed the add_noise_textures branch from b5b1745 to f12a1b8 Compare September 14, 2018 13:24
@akien-mga akien-mga merged commit 2aad7f1 into godotengine:master Sep 14, 2018
@akien-mga
Copy link
Member

Thanks a ton! :)

@ghost
Copy link

ghost commented Sep 14, 2018

Fantastic! XD Going to try it out soon.

@PetePete1984
Copy link
Contributor

PetePete1984 commented Sep 19, 2018

Before it's finalized in a release build: the correct spelling would be "persistence", not "persistance".
https://github.com/godotengine/godot/search?q=persistance&type=Code
Only concerns the new module as far as I can see.

@smcameron
Copy link

Hello.

If the concern is the patent issue with simplex noise then based on my estimation it should expire on 2021 so we can be strategical about naming convention.. Besides, OpenSimplex implementation could be replaced with Simplex in the future.

An argument against changing the underlying noise function in the future would be that this would change the behavior of any programs relying on it for e.g. deterministic procedural generation, which for some programs (e.g. something along the lines of No Man's Sky) this would amount to a breaking change.

@santouits
Copy link
Contributor

I also think that it should be named Open Simplex Noise because:

  • That is it's correct name.
  • It's a different algorithm.
  • There is also a wikipedia page.
  • It doesn't hide that there is an open alternative to the simplex noise, so it is important to the opensource culture.
  • If in the future simplex noise patent expires, it can be added too without breaking old projects.

@JFonS
Copy link
Contributor Author

JFonS commented Sep 20, 2018

I have no preference on the name other than SimplexNoise being shorter. Feel free to open a PR with the change or an appropriate issue to discuss this.

@Wircoark
Copy link

Wircoark commented Sep 22, 2018

Are noise textures supposed to work within the Visual Shader Editor? I added a noise texture, fed it UV´s and put it in the Color output of a CanvasItem shader but it just shows up black. I tried right clicking the noise texture and tried to "edit" it so I could choose "SimplexNoise" like you would if you just add this texture to a Sprite but no settings are exposed. Figured I´d mention it here if it´s a bug, or maybe this is a bug of the Visual Shader editor, rather than the noise texture?

@JFonS
Copy link
Contributor Author

JFonS commented Sep 22, 2018

@Wircoark It's a quirk of the visual shader editor. If you use the constant texture node and you create a new texture from the visual node itself then you have no way to modify it's parameters (gradient or curve textures have the same issue).

I might try to fix it, but for the moment you can workaround it by creating a new NoiseTexture resource in memory (green plus icon in the inspector), saving it to a resource file and then loading it in the visual shader node. This way you will be able to open the resource's inspector through the file system dock and edit all of it's parameters.

@SethRzeszutek
Copy link

SethRzeszutek commented Nov 19, 2018

I am on the Alpha 3.1, when using the reference code from the docs I come up with OpenSimplexNoise not being declared in the current scope errors. Running the simple code in the Docs fail.
More information is on this is here: https://godotengine.org/qa/35936/issue-using-opensimplex-godot-alpha-doesnt-register-module.

@Zylann
Copy link
Contributor

Zylann commented Nov 19, 2018

@SethRzeszutek It was added after 3.1 alpha1. Try 3.1 alpha2, it has simplex noise in it: https://downloads.tuxfamily.org/godotengine/3.1/alpha2/

@SethRzeszutek
Copy link

I am on the alpha, I downloaded it yesterday. Even the about section says GODOT 3.1.alpha, is there an alpha2?

@Zylann
Copy link
Contributor

Zylann commented Nov 19, 2018

@SethRzeszutek it seems the editor doesn't display which alpha it is, but you should try the official alpha2 link I provided above, this one definitely has OpenSimplexNoise.

@SethRzeszutek
Copy link

That link allowed for me to use openSimplex, I guess I somehow downloaded the wrong alpha? Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants