Page 1 of 2

Snow shader for mountains

Posted: Wed Oct 06, 2010 11:47 pm
by FakeShamus
so, in my first attempts at ISL I have figured out how to use the shading normal of my mountains here to color the flatter areas like snow while leaving the steeper angles more of a rock color. this seems to work pretty well, but I would really like to be able to make the rock and snow completely separate materials and just blend them by using the same technique. here is my (probably very overly-complicated) code that gives the results in the image below (the mountains are a displaced plane using a heightfield exported from terragen):

Code: Select all

<albedo>
				<shader>
					<shader><![CDATA[
			def Zangle() real:
				dotk(normalWS())
			
			def Snow() real:
				0.8
			def StoneX() real:
				0.11
			def StoneY() real:
				0.10
			def StoneZ() real:
				0.09

			def Zless() bool:
				gte(Zangle(), 0.6)

			def Xcheck() real:
				if(Zless(),
				Snow(), StoneX())
			def Ycheck() real:
				if(Zless(),
				Snow(), StoneY())
			def Zcheck() real:
				if(Zless(),
				Snow(), StoneZ())

                  def eval(vec3 pos) vec3 :
			vec3(
				Xcheck(),
				Ycheck(),
				Zcheck()
			)]]></shader>
				</shader>
			</albedo>

and here is my attempt to implement the same idea into the <blend> element of the material, which gives me only one of the materials or the other, (the "Zless() bool" only changes the material if it is set higher than 1) :

Code: Select all

<blend>
			<a_name>snow</a_name>
			<b_name>stone</b_name>
			<blend>
				<shader>
					<shader><![CDATA[			def Zangle() real:
			dotk(normalWS())

			def Zslope() bool:
				gte(Zangle(), 0.8)

                  	def eval() real :
				if(Zslope(),
				0.0, 1.0)
			]]></shader>
				</shader>
			</blend>
			<step_blend>false</step_blend>
		</blend>
any help in this case (and/or insight on how to improve on the concept) would be much appreciated.
thanks!

Re: Snow shader for mountains

Posted: Wed Oct 06, 2010 11:49 pm
by fused
:O

wow. very nice shader.

edit: unfortunately you can not use the normal shader functions in the blend channel currently

Re: Snow shader for mountains

Posted: Thu Oct 07, 2010 12:10 am
by FakeShamus
bummer, wasn't aware of that.
will it work with exponent or bump? if there was some other way to differentiate the snow from the rock texture at least that would be a start.

Re: Snow shader for mountains

Posted: Thu Oct 07, 2010 12:18 am
by fused
It won't work with any channel that takes a displacement parameter, afaik. These channels are blend, displacement and bump.
It should work with any channel taking wavelength dependent or independent parameters. So yes, you could use it on exponent.

Re: Snow shader for mountains

Posted: Thu Oct 07, 2010 12:50 am
by zeitmeister
Wow, this looks so natural! Really natural spreading of the snow! Best I've ever seen so far!
Could you add custom values for the elevation values, or does the shader evaluate that by itself? An now, the typical slightly sparcling could be added in the exponent channel...
Keep it up, that's gonna be fantastic!

Re: Snow shader for mountains

Posted: Thu Oct 07, 2010 1:53 am
by FakeShamus
thanks,
you can control the snow coverage by changing the "Zless() bool" comparison value (set to 0.6 in the code above) which basically controls how steep the surface can be before it switches from the snow color to the rock color (I think a noise function could also be added in there somewhere to randomize the break up some) but there is no elevation parameter yet, so it just covers all of the surfaces evenly depending on the slope. elevation settings would be nice. but I'm a total beginner at this stuff.

Re: Snow shader for mountains

Posted: Thu Oct 07, 2010 2:07 am
by Borgleader
That....IS EPIC! :shock:

Re: Snow shader for mountains

Posted: Thu Oct 07, 2010 2:50 am
by zeitmeister
Depending on the slope:
Well, that's exactly what snow does. Plus, a little bit more, because snow sticks in some cases... but as I said, that's really fantastic.
Maybe a very small, but high reflective perlin noise in the exponent?

Re: Snow shader for mountains

Posted: Thu Oct 07, 2010 3:20 am
by FakeShamus
Maybe a very small, but high reflective perlin noise in the exponent?
that's a good idea, I'll have to play around with that
That....IS EPIC!
all epicness due to Terragen and Indigo. but I have been waiting for a while to be able to create this ISL snow effect. waaaay better than earlier attempts using texture maps: http://www.indigorenderer.com/forum/vie ... ins#p87163

Re: Snow shader for mountains

Posted: Thu Oct 07, 2010 3:44 am
by kdarius
could you please post a material of this or please explain how i would implement this? I asume its not just cut and paste into notepad save the file and use as external.. is it?

Re: Snow shader for mountains

Posted: Thu Oct 07, 2010 3:47 am
by Borgleader
FakeShamus wrote:all epicness due to Terragen and Indigo. but I have been waiting for a while to be able to create this ISL snow effect. waaaay better than earlier attempts using texture maps: http://www.indigorenderer.com/forum/vie ... ins#p87163
Terragen...I should learn to use that!

Re: Snow shader for mountains

Posted: Thu Oct 07, 2010 9:36 am
by galinette
Excellent!

Re: Snow shader for mountains

Posted: Thu Oct 07, 2010 1:23 pm
by OnoSendai
I've made some changes so that normalWS() can now be called inside displacement parameter shaders. Currently it will only give correct results when used for evaluating the blend factor.

So with these changes you should be able to use the normal to blend between different materials, like so:

Code: Select all


  <material>
    <name>a</name>

    <diffuse>
      <albedo>
        <constant>
          <rgb>
            <rgb>0.1 0.8 0.1</rgb>
            <gamma>1</gamma>
          </rgb>
        </constant>
      </albedo>
    </diffuse>
  </material>

  <material>
    <name>b</name>

    <phong>
      <ior>1.5</ior>
      <exponent>100</exponent>
      <diffuse_albedo_spectrum>
        <rgb>
          <rgb>0.8 0.1 0.1</rgb>
          <gamma>1</gamma>
        </rgb>
      </diffuse_albedo_spectrum>
    </phong>
  </material>
  
  <material>
    <name>default</name>

    <blend>
      <a_name>a</a_name>
      <b_name>b</b_name>
      <step_blend>false</step_blend>

      <texture>
        <path>blackrose_pattern.jpg</path>
        <exponent>2.2</exponent>
        <uv_set>default</uv_set>
      </texture>

      <blend>
        <shader>
          <shader>
            <![CDATA[
						def eval() real :
							if(dot(normalWS(), vec3(0.0, 0.0, 1.0)) > 0.3,
                1.0,
                0.0
              )
						]]>
          </shader>
        </shader>
      </blend>
    </blend>
  </material>

Re: Snow shader for mountains

Posted: Thu Oct 07, 2010 2:00 pm
by CTZn

Code: Select all

:o

Re: Snow shader for mountains

Posted: Thu Oct 07, 2010 2:24 pm
by FakeShamus
oh sweet! thanks for that.
I like how your version basically decimates my feeble attempts at code.