Coder Social home page Coder Social logo

Comments (6)

stegu avatar stegu commented on August 15, 2024 1

from webgl-noise.

stegu avatar stegu commented on August 15, 2024

from webgl-noise.

piranha771 avatar piranha771 commented on August 15, 2024

Okay I may have been confusing with this sobel stuff.
Currently I use sobel to build normals out of noise. It's super simple:

float3 height_to_normal(sampler2D tex, float size, float2 uv, float strength) 
{
	float step = 1.0/_Resolution;

	// Get 8 UVs around the current UV;
	float2 tlv = float2(uv.x - step, uv.y + step); 
	float2 lv  = float2(uv.x - step, uv.y 	    );
	float2 blv = float2(uv.x - step, uv.y - step);	
	float2 tv  = float2(uv.x 	,uv.y + step); 
	float2 bv  = float2(uv.x 	,uv.y - step);
	float2 trv = float2(uv.x + step, uv.y + step); 
	float2 rv  = float2(uv.x + step, uv.y       );
	float2 brv = float2(uv.x + step, uv.y - step);

	// Get the values from these 8 UVs
	float tl = tex2D(tex, tlv).a; 
	float l  = tex2D(tex, lv ).a;
	float bl = tex2D(tex, blv).a;	
	float t  = tex2D(tex, tv ).a; 
	float b  = tex2D(tex, bv ).a;
	float tr = tex2D(tex, trv).a; 
	float r  = tex2D(tex, rv ).a;
	float br = tex2D(tex, brv).a;

	// Do the sobel operation
	float dx = tl + 2.0 * l + bl - tr - 2.0 * r - br;
	float dy = tl + 2.0 * t + tr - bl - 2.0 * b - br;

	// Convert to normal
	return normalize(float3(dx, -dy, 1.0/strength));
}

So what it does is this:

h2n

This is what I'm currently doing. But I saw in your wiki page that it is possible to calculate the normal map directly from the analytical derivative, so I can skip the noise2normal stuff and use the analytical derivative to create a normal map instead.

  	// 2-D tiling simplex noise with rotating gradients and analytical derivative.
  	// The first component of the 3-element return vector is the noise value,
  	// and the second and third components are the x and y partial derivatives.
  	//
  	float3 psrdnoise(float2 pos, float2 per, float rot)

What to do with the derivatives to get a normal map?

d2n

I tried to normalize them normalize(float3(dx, dy, 1.0)) but its not a valid normal map.

from webgl-noise.

piranha771 avatar piranha771 commented on August 15, 2024

analytic derivatives give you the local idealized rate of change across one unit of distance (1.0)
[...]
you paint a pattern using 0.3noise(4.0u, 6.0v), the local gradient in
texture coords is 0.3
vec2(4.0,6.0) times the analytic gradient.

This was the answer I was looking for! Thank you so much!
Works and looks perfect now :)

from webgl-noise.

stegu avatar stegu commented on August 15, 2024

from webgl-noise.

stegu avatar stegu commented on August 15, 2024

Even though the issue was resolved, I am keeping the thread open because it's informative.

from webgl-noise.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.