Is there any alternative ddx ddy for calculating normals when use DistanceToNearSurface?

This version is more correct and smoother
Old V1


New V2

much less black artefacts

1 Like

Maybe you will be interested. I am trying to change the waveform. I found this method in YouTube



Now itā€™s just a WPO wave

1 Like

I left this value as a parameter for more fine tuning in the future.
5
What is the difference between Amplitude and WPO Scale? isnā€™t that a duplication? Visually, there is a slight difference, but the WPO Scale has no effect on the normal. I left WPO Scale as fixed value

Yes, less math means less precision errors. For example the arctan fast is an approximation and we have eliminated it.

Looks nice, I particularly like the front wave.

Not exactly a duplication. It allows for the WPO to be changed in strength without reducing the amplitude which would in turn weaken the normal. This was mostly just for testing when I wanted to temporarily turn off/down the WPO.

Itā€™s mostly redundant because we can already independently scale the normal from the amplitude but if the amplitude is 0 then the normal is flat and canā€™t be scaled.

If you have no use for it I would replace it with a switch that simply disables WPO altogether while keeping the wave, since thatā€™s all it was good for. I didnā€™t do it that way because Iā€™d have to recompile the shader every time I toggled the switch which slows down testing.

An example use would be to slowly decrease WPO beyond a certain distance until it reaches zero, then switch to a version with it turned off entirely. Being able to do this without adjusting the amplitude allows the wave to continue to look the same in light and reflection even as we prepare to switch to the cheaper version of the shader.

You can still use the DFG to generate normals for this wave, as it will still have the same fundamental property that the sine wave did, where the wave front normals are pointing in the direction of the DFG and the wave back pointing in the opposite direction.

You should also be able to achieve something similar with a the old sine wave too, you would just have to shape its inputs.

Good idea

Itā€™s cool that I can generate waves even for a rectangle without a dense mesh. But their distance is not so big

For example, here I am shaping the sine wave using a curve asset. You could do this with math, but a curve allows for us to very easily control the x in our sine(x) to make it non-linear and create any shape of wave. And since it is still technically a sine wave, the previous normal calculation should work without modification.

I tried to reproduce this method, but my wave does not repeat. And accordingly, it is not possible to animate

You would need to set the sampler type to wrap in order for it to repeat. As you can see in my screenshot, it is repeating.
It can still animate, you would just need to animate the position of the texture too.

It also doesnā€™t need to be a texture. A similar gradient could be created using nodes. The point is just that any non-linear input will lead to an altered waveform.


Hereā€™s an example that animates. By default curve atlases donā€™t wrap their UV coordinates which is why this setting must be altered.

This approach also allows you to encode multiple waveforms into the texture in the RGB channel, or as extra indices in the atlas, and sample them in different times and locations.
Hereā€™s a single sine function that is sampling two different curves at the same time in different directions (one along the U direction and the other along the V direction):


This particular demo may not seem that useful at a glance, but the basic premise would allow one to change the waveform based on whatever they wanted. Some examples might be global parameters like weather, or local parameters - such as making the wave form different depending on if the distance field is being generated by the beach or a rocky cliff.

3 Likes

I literally tabbed out, 1min later tabbed back and it was different.

I love this place.

EDIT: In your pic above, I see the curve on the right-side, but in the material graph, ???. Color-coded right, purple? I see a constant and a texure sampleā€¦ Did I miss something?

1 Like

Curves assets are sampled as textures via a Curve Atlas asset. The curve on the right propagates into the texture sample on the left instantly as changes are made. The appended value is the index in the atlas to sample, as it can hold numerous curves per index and per color channel.

TY. I knew of them, what they could do but never explored them.

Much appreciated.

1 Like

Very power and underutilized. Not UE, but Horizon Zero Dawn used curve atlases to colorize their foliage and some props by biome using gradient mapping if Iā€™m not mistaken. This allowed for assets to use only a grayscale texture channel for their base color as a lookup table and could automatically colorize themselves based on the biome index.

Thanks! I always think of things like this, how to pack data, do more w/less; good to know Iā€™m on a right trackā€¦

Is there a paper/video where they talk about this?

Hereā€™s the GDC slides. There should also be a YouTube Talk or two.

The Vegetation of Horizon Zero Dawn - Amazon AWS https://ubm-twvideo01.s3.amazonaws.com/o1/vault/gdc2018/presentations/gilbert_sanders_between_tech_and.pdf

1 Like

Everything worked in WPO, it looks great. Shore waves are generated and easily modified.
Thanks for showing me a new tool!
In theory, I can make masks for foam using curves.

When I add curves to normals, errors appear. Tried to fix it with MakeFloat2 but it didnā€™t work.
Maybe the problem is that the cosine has a different waveform and I need to edit it. But now the problem seems to be something else
Iā€™m tired of the lack of knowledge))

1 Like

This is what I got when I started changing the parameters of the curve. But all this parameters does not work correctly




The curve isnā€™t the shape of the wave. The curve is the shape of the input of the wave. Think of the value of the curve as (x) in the function y = sin(x).
To get the desired shape, you need to understand the relationship of the input and the output.
And yes, youā€™d need to use this curve to modify the waveform of both the sin and the cos.

If you want to directly shape the curve itself instead, we donā€™t need sine at all - but weā€™d have to find the normal another way because we canā€™t rely on the relationship between sine and cosine to find the normal. The reason the last method works is because cos is equal to the tangent of sin, and the normal is perpendicular to the tangent.

In order to find the normal mathematically the curve needs to be a defined function, so that you can solve for itā€™s derivative (tangent) mathematically as well. If our surface is an image (like the curve or a heightmap) you can also approximate the derivative by sampling it at two of the closest points possible along that curve. This would give us the rate of change between these two points, aka the slope. The slope is essentially the tangent, and with that tangent we can solve for the normal.

Hereā€™s an example of a wave driven by a curve texture only with no parametric function whatsoever. Instead, the normal is found by sampling the curve with a tiny offset and measuring the difference. Small mistake in the screenshot here is that the Curve index should be appended after the offset, not before - as this would cause the index to be offset too in error. I didnā€™t notice because this curve atlas only had one index.

If youā€™re tired of a lack of knowledge in this area, Iā€™d suggest getting comfy with linear algebra, trigonometry and at least some basic calculus.

And to demonstrate my earlier point about being able to dynamically morph between custom waveforms using curves, hereā€™s a gif of a slightly modified version of the last example that has two curves in the atlas and alternates between them over time, but this could also be done over space. Using the offset technique above it has accurate normals during the transition although it may be hard to tell due to the color.

1 Like

Hereā€™s an example of that, which is more visually interesting. In this case there are two identical waveforms, staggered from each-other and then it alternates between them by a radial UV map. The idea here was to create something that resembles ferrofluid. But the point is the waveform doesnā€™t need to be identical across space as this demonstrates.

3 Likes

Thank you for spending your time and giving so many options to solve this problem. I tried all the options and the last one is more flexible for me.

1 Like