Skip to content

Conversation

bhouston
Copy link
Contributor

For advanced post processing effects I need a high quality 3D and 1D noise generator. I suspect going forward we will also require more procedural effects (fractal noise, soft edges, marble, wood, etc.)

So I have started a procedural.glsl shader and I've contributed an example for visualizing easily these procedural textures by themselves.

The first example is a very high quality noise function.

Based on the code here: http://stackoverflow.com/a/4275343

@bhouston
Copy link
Contributor Author


<script src="js/postprocessing/EffectComposer.js"></script>
<script src="js/postprocessing/ManualMSAARenderPass.js"></script>
<script src="js/postprocessing/TAARenderPass.js"></script>
Copy link
Contributor

Choose a reason for hiding this comment

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

needed for this demo?

@bhouston
Copy link
Contributor Author

Another example link that is upgraded to use the random generator:

http://ci.threejs.org/api/pullrequests/8603/examples/webgl_materials_envmaps_hdr.html

Others that can be upgraded I think to use the new random generator are FilmShader, SSAO (but that needs a lot of work), and DOF shaders. If you guys approve of this approach (procedural.glsl) I can modify Film and DOF to use this. SSAO is a big project so that is clearly a separate PR.

@mrdoob
Copy link
Owner

mrdoob commented Apr 11, 2016

This is handy indeed, but I'm not sure it should go in src...

@bhouston
Copy link
Contributor Author

You're right, it probably doesn't.

We probably need to figure out a way to support individual *.glsl files in the examples/js folder structure and somehow those *.glsl files to support #include statements that resolve to glsl files outside of the /src structure -- so I could have a procedural.glsl outside of /src that can be included into other *.glsl files outside of src. Right now glsl snippet sharing isn't possible in the /examples and also editing glsl as strings embedded inside JavaScript is pretty brutal. I wish I had more time...

@mrdoob
Copy link
Owner

mrdoob commented Apr 11, 2016

I guess a hacky way would be to just do THREE.ShaderChunks[ 'procedural' ] = 'foo'; in the example itself...

@tschw
Copy link
Contributor

tschw commented Apr 11, 2016

I guess this is more of a noisy noise for image processing rather than a noise a la Perlin for procedural texturing and modeling purposes (one that becomes smooth when zooming in)?

@bhouston
Copy link
Contributor Author

I guess this is more of a noisy noise for image processing rather than a noise a la Perlin for procedural texturing and modeling purposes (one that becomes smooth when zooming in)?

Yes, it is just a pseudo random number generator - that somehow works sufficiently well for when you need "random"-ish sampling while being fast and small.

@bhouston bhouston changed the title create procedural glsl and an example to show off the noise textures. Add high quality rand() function to common.glsl and an example to show off the noise textures. Apr 12, 2016
@mrdoob
Copy link
Owner

mrdoob commented Apr 12, 2016

I like this better now 😀

<a href="http://threejs.org" target="_blank">three.js</a> - Procedural Effects Example by <a href="https://clara.io" target="_blank">Ben Houston</a><br/><br/>
</div>

<script id="procedural-vert" type="x-shader/x-vertex">
Copy link
Owner

Choose a reason for hiding this comment

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

This file has some space/tabs mix up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found a plugin for atom.io called tab-to-spaces, which allows converting back and forth between tabs-spaces really easily.

@bhouston
Copy link
Contributor Author

One more minor update coming...

@bhouston
Copy link
Contributor Author

Okay, I think I've got the minor bugs fixed and the spaces/tab issues addressed.

@tschw
Copy link
Contributor

tschw commented Apr 12, 2016

@bhouston

Yes, it is just a pseudo random number generator - that somehow works sufficiently well for when you need "random"-ish sampling while being fast and small.

Still very useful IMO.

I guess, you might get away with less for the implementation. See

https://www.shadertoy.com/view/4ssXRX
https://www.shadertoy.com/view/4djSRW

and maybe more amongst the search results on "random".

@bhouston
Copy link
Contributor Author

@tschw Awesome! It is exactly why I want a rand() funciton in the core of ThreeJS so we can find an optimal one. :)

I believe this one here: https://www.shadertoy.com/view/4ssXRX is actually the same one that is implemented. I had expanded it originally because of this doc here: http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/ But then today I collapsed it and @WestLangley reminded me of why the expanded version needs to be used by re-discovering this doc.

The second stuff is interesting. I am okay with this function AS IS as it serves my purposes -- it is sufficient. I would love others to continue to find more optimal solutions or ensure that it works properly on mobile devices, but I need to get back to implementing a high quality universal SAO algorithm (which is my motivation for the recent depth work and this rand() stuff.)

@tschw
Copy link
Contributor

tschw commented Apr 12, 2016

@bhouston

http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/

If that's what's implemented, it should be minimal enough. Turns out I've been looking at an older version using up a sampler.

The second stuff is interesting.

Seems basically the same thing, just using a bare sawtooth waveform.

face = direction.y > 0.0 ? 1 : 4;
}
return face;
vec3 absDirection = abs(direction);
Copy link
Owner

Choose a reason for hiding this comment

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

This file is now using double tabs instead of single tabs for indentation.
With that fixed it should be good to go! 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. :)

Copy link
Owner

Choose a reason for hiding this comment

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

Sweet!

@mrdoob mrdoob merged commit db76528 into mrdoob:dev Apr 12, 2016
@mrdoob
Copy link
Owner

mrdoob commented Apr 12, 2016

Thanks!

</script>
<script id="noiseRandom1D-frag" type="x-shader/x-fragment">
#include <common>
#include <packing>
Copy link
Owner

Choose a reason for hiding this comment

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

Hmm, I don't think these shaders are using <packing>?

@bhouston bhouston deleted the procedural branch May 12, 2017 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants