Masking Fake Stones

Started by monks, June 26, 2012, 07:42:55 PM

Previous topic - Next topic

monks

Hi, I'm trying to use multiple layers of fake stones using surface layers. I'm controlling slope distrib via the surface layers and the terrain normal slope key. How would I go about masking the fake stones so that they don't end up stacking up on top of each other?
I've tried using the output from the fake stones as a mask, inverted, into the blend shader of the next surface layer, each mask added in series, but it's not working. The fake stones distrib is driven by a power fractal, and I've also tried using that output as a blend mask. Same results.

I was looking at the 'scalar to boolean' to try and convert the power fractal colour output to an on/off mask, so that I'm guaranteed a more accurate mask. That's not working to plan though as the colours in the power fractal are not black and white.

Anybody got any ideas how to go about this?

monks


Tangled-Universe

This is one of the FAQ, thus easy to find using the search function in the forum ;)

http://www.planetside.co.uk/forums/index.php?topic=11331.msg116207#msg116207

The output of the bottom merge shader needs to go into the child layer port of a surface layer.
Make sure the surface layer has no colour and you may need to enable "smoothing" in the surface layer.
This reverts the surface to the smoothed version of the last compute terrain before that specific surface layer and thus cancelling out displacements.
If you don't use this then the fake stones will incorporate the displacements of the terrain or small displacements after the compute terrain (for example).

billhd

A simple approach is to apply the stone layers such that smaller stones go underneath the bigger stones on the terrain, thus in the network the smaller stone nodes would cascade into the large ones in size succession. 

I too tried the masking, but for a different reason- I wanted to use a fake stone shader with big stones to make a mask that would be "expanded" in grayscale terms so that I could use it to distribute smaller stones right around the large stones, "chips off the old block".  I was not successful, tried scalar to color and could not get it but never addressed the forum on the question - I'm curious if anyone has a tip.  Bill

monks

Thanks Tangled, I'll take a look at it. billld I'm also wondering about the other method- of controlling placement via mask manipulation- would be useful for other things too. It would be good to be able to turn all non black areas to white- which I think is what the scalar to boolean does, but I had problems getting 1 and 0. I've no doubt it can be done. I don't really understand the interface or the colour adjust node- it's remapping? Which slider maps what? The method Tangled linked looks simpler.

monks

penboack

#4
I've been having some problems with Fake stones as well.

Using a network of Fake Stones shaders before the last (only in this case) Compute Terrain node I was able to get the Populator to populate on top of the stones, and to use the Fake stones shader output as a mask for a white (boring) Surface Layer shader. Obviously this isn't so useful with trees! but it would be useful for adding a population of rocks on top of boulders. [Scene Fake-Stones_1_v2]

[attachimg=1]

The problems comes when I add Fake Stones to a Fractal Terrain and want to use the output of the last node in the Fake stones network as a mask for a Surface Layer shader.

In the test scene the Fake stones should be white, and the terrain the default colour, but it doesn't work. What I am struggling with is how to update the texture coordinates so that the masking works, or technically where to put a Compute Terrain node or nodes to update the texture coordinates.

[attachimg=4]

I tried adding an additional Compute Terrain node after the Fake stones shaders and then merging the Fractal terrain, but that didn't produce the expected result, instead some of the white surface layer texturing still appears on the terrain. [Scene: Fake-Stones_2_v3]

How do you add Fake stones to a terrain before the Compute Terrain node and use the Fake stones shader output as a mask for texturing?

monks

#5
Penboack, looking at these to get some tips. :) In both versions I think the smallest fake stone are plugged into the wrong node. Is this affecting anything?

monks

Hetzen

Does un-checking Vary Density in the Fake Stones shader help? There is/was a bug with texture alignment.

Tangled-Universe

#7
There was an error in your setup, but that didn't affect anything (you had one fake stone layer as merge controller, instead of 'shader A')

Ok, here it is:

You have a fractal terrain and to that you add fake stones.
However, the data-flow doesn't provide information from the compute terrain where the fake stones actually have been added.
Both terrain and fake stones were calculated at once and share all the same coordinates.
This results in a misalignment when you use the fake stones as a blendshader downstream in the network, since the fake stones at that point weren't supplied with proper texture coordinates and normals, yet.

I'll try to explain, but it's a bit hard to do that easily, so I'll do my best :)

What you need is to create 2 stages, as follow:

1) create terrain and compute
Now the terrain has been calculated first, providing base texture coordinates and normals to perform proper masking on for altitude and slope respectively.

2) add fake stones after the computed terrain fractal
These fake stones are now created onto the terrain which has properly calculated texture coordinates and normals as a base.
The resulting texture coordinates and normals will align with the base terrain.

3) compute again
Because the stones are separately added the compute terrain will update the texture coordinates and normals with the data provided from the fake stones.
Now the terrain and fake stones are "merged" as final* texture coordinates and normals of the terrain and thus will align properly.

In other words: because the fake stones addition is calculated again the program is now aware of the difference between the terrain and the added fake stones when you use the fake stones as a blendshader downstream in the network.

(*final: in this case NOT the same to final position/normal as seen in the distribution shader. Final position/normal is the state of the data stream when computed in the planet node)

4) shade and/or blend for fake stones

I'll read this message again a bit later and try to make it more clear.
Anyway, the images speak for themselves.

Mask_stones_misalignment.jpg shows what happens when you do not calculate everything separately. As you can see the white colour is misaligned because it follows the terrain instead of the terrain + fake stones.

Cheers,
Martin

penboack

Thanks Martin.
I understand it now. It is not easy to explain these things.

Aside from having Compute Terrain nodes in the correct places, the key seems to be to use a Surface Layer node's child input to add in the Fake Stones network output so that it overrides the terrain, rather than using a Merge node which sort of mixes up the texture coordinates. For a while now I've been struggling a bit with the whole problem of generating Terrain features and using the sub-network that creates them as a mask for texturing. I can see that this technique could be very useful for solving these types of problem.

Thanks to both of you for spotting the mistake in my Fake Stones network.

Tangled-Universe

Quote from: penboack on June 29, 2012, 05:23:54 AM
Thanks Martin.
I understand it now. It is not easy to explain these things.

Aside from having Compute Terrain nodes in the correct places, the key seems to be to use a Surface Layer node's child input to add in the Fake Stones network output so that it overrides the terrain, rather than using a Merge node which sort of mixes up the texture coordinates. For a while now I've been struggling a bit with the whole problem of generating Terrain features and using the sub-network that creates them as a mask for texturing. I can see that this technique could be very useful for solving these types of problem.

Thanks to both of you for spotting the mistake in my Fake Stones network.


You're welcome, no problem.

The surface layer is just a base. I'm not really sure what you mean by 'overrides'. It's just a placeholder for the fake stones to exist on. But indeed, you're right that using a merge shader probably isn't right. I haven't tried that yet actually in this setup. You can replace the surface layer with a merge shader and see if it still works.
The most important aspect is the 2-step calculation.

The most important reason for a surface layer is something else, actually. For example, you perform medium scale and quite some small scale displacements after the compute terrain. That's most of the times not a real problem.
However, if you add in fake stones then they will incorporate those displacements, resulting in messed up stones.
The surfacelayer has an option called "smoothing" which tells the shader (surface layer) to NOT use the current state at that point in the data-stream, but look up for the nearest computed terrain up in the network and use the terrain and texture coordinates at that point.
By that you will by-pass the medium and small scale displacements for your fake stones, but also allows for completely separate shading of your stones :)

bobbystahr

Well, out of inspiration today I deceided to dive into this one and am floundering. I managed to get the FS nodes set up as described but cannot for the life of me, figure out how to apply different textures to each size of FS....Help pleeeeeze, and thanks up front....attached is my .tgd if someone could fix my set up...seems the only way I learn is by seeing sometimes....
something borrowed,
something Blue.
Ring out the Old.
Bring in the New
Bobby Stahr, Paracosmologist

inkydigit

Hi Bobby, the only way really that I have found is to have separate surface layers for each (set) of fake stones...trying to find an easier way has been almost impossible for me!
:)

bobbystahr

Quote from: inkydigit on June 29, 2012, 11:58:32 AM
Hi Bobby, the only way really that I have found is to have separate surface layers for each (set) of fake stones...trying to find an easier way has been almost impossible for me!
:)
Where do I put them mate?...I can't seem to get it to work from the Shader Tab...
something borrowed,
something Blue.
Ring out the Old.
Bring in the New
Bobby Stahr, Paracosmologist

monks

Martin's explanation did help a lot. Bobby that's exactly what I ended up looking into- still trying to do that now  :D

monks

monks

#14
Bobby. you might try this http://www.planetside.co.uk/forums/index.php?topic=2573.msg25643#msg25643

Plug two power fractals into a colour mixer and plug the output into your rock surface shder. Do that for each stone size and that might work...testing it now.  Maybe not the best way, think surface layers would be better, but it looks like a possible improvement.

//I think the merge shader is better than the colour mixer.
For some reason my imag keeps failing security checks so here's a link.

Am I right in saying that you can stack surface layers like this with a series of child nodes going into the fakes stones shader input?
[link expired]
monks