Shader based on face angle

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Display Modes
  04 April 2013
Shader based on face angle

Im looking for what I think the mountain shader should be, maybe I haven't messed with it enough, but it was not giving me what I though it would do.
All I am after is a way to blend two textures based on the objects face angle. Example would be a mountain outcropping, faces pointing up get grass, and things that are say 90 will be dirt, and even better faces that point down will get rocks.
I was messing with sample info and trying to get that to work, similar to a camera facing ratio shader but no dice. Anyone know the secret recipe?
  05 May 2013
There's two ways to do it, one using sampler info, and the other way using a baked normal map, the results will basically be the same.

The sampler info node can give you the camera normal (normals with respect to camera). If you use the vectorProduct node, plug in the camera normal and matrixEyeToWorld attributes of the sampler info, you will have world space normals. You can also use texture map extraction and extract a normal map (projected onto a plane). This probably isn't the best way though, using the sampler info would allow you to have a fully procedural workflow.

Basically, the y component of the world normal will tell you the slope of a surface. If the y component is 1 (and the vector is normalized) the face normal points straight up, if it's 0, then the face normal is pointing solely in the XZ plane (horizontally). If it's -1 the face is pointing straight down.

Taking the dot product between the normal vector and the vector 0 1 0 using the vectorProduct node, and checking the normalize output box will give you the y component of the face normal. Some of the results may be negative, if the face normal points down. Keep that in mind when driving your ramps or whatever else.
  05 May 2013
Hey, sounds like you're on the right track.

There's a common method which involves using the sampler info node and a ramp to shade based on the facing angle.

I've attached a screen grab below. Basically you need to connect the "facingRatio" attribute from the sampler info to the "uvCoord>vCoord" of the ramp. You can then apply different colours/textures to different bits of the ramp.

  05 May 2013
Facing ratio is based on view angle, so it won't work for what he wants.

Instead try using a snow texture. You can texture the two colors. Rotating the 3D placement node rotates the up direction for the snow. You can also do things likes texture the threshold to make the boundary irregular. Or if you have a bump map you may wish to connect the bump outNormal to the snow normalCamera.
  05 May 2013
I have this tension node. In one of its modes it can measure angles between edges and generate map based on that. This will allow you achieve what you are after.
  05 May 2013
I think the snow node will do it for us. I would however be interested in this tension node, sounds very useful. Thanks for all the replies!
  05 May 2013
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 03:30 PM.

Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.