Page 2 of 4

Re: [REQ] Indigo instance color variation shader

Posted: Tue Aug 05, 2014 7:19 am
by Zom-B
Ok, now I got it :oops:

Re: [REQ] Indigo instance color variation shader

Posted: Sat Mar 07, 2015 1:59 am
by zeitmeister
BUMP!!! :evil:

I am not a coder, and I am giving up. Really. :shock:
Guys, I need a shader similar to the brick shader. Only for instances.

Variant A:
I provide the shader a number of textures. Each instance (-ID) gets a random texture from the pool.

Variant B:
I provide only one texture to the shader. Each instance gets a slightly gamma- and color shift RANDOMLY by instance-ID.
A shaded parameter should be the gamma shift range and the color shift range.

Could this be soooooooooooo difficult?
I even don't find in ANY ISL documentary how to implement a texture variable into ISL. And if I need vec3 for what I want or not.


Please help me and us for building an easy-to-use Instance Color Variation Shader!!!
Thank you in advance!

Re: [REQ] Indigo instance color variation shader

Posted: Sat Mar 07, 2015 2:10 am
by bubs
+1
Ono did all the code for me for the brick so I'm afraid I can't help :oops:
As an archvizer I think this would prove very useful, I'd particularly love to see galinette's ideas about glass panels implemented.

Re: [REQ] Indigo instance color variation shader

Posted: Sat Mar 07, 2015 3:49 am
by zeitmeister

Code: Select all

def eval(vec3 pos) vec3 :
  let
    r = real(objectId())
    base_col = vec3(0.6, 0.4, 0.4)
	
	# Get UV coords
		uv = getTexCoords(0)

	# Pick a random texture index
		NUM_TEXTURES = 3
		# tex_index = floorToInt(gridNoise(vec2(x(uv) + 100000.0, y(uv) + 1000000.0)) * real(NUM_TEXTURES))
		tex_index = floorToInt(noise(vec2(x(uv), y(uv))) * real(NUM_TEXTURES))

		random_scale = 2
  in
	
	sample2DTextureVec3(tex_index, uv) * random_scale

    #base_col + vec3(
      #fract(r * 45.345),
      #fract(r * 4.57),
      #fract(r * 908.3)
    #) * random_scale
Really NO IDEA what is going on here.
Regarding the tex_index I can't simply output a random value of the read NUM_TEXTURE... no chance. Tried everything.
Plus, the "sample2DTextureVec3()" doesn't accept FRACT-modifiers as above at the very end... I am so helpless...

Re: [REQ] Indigo instance color variation shader

Posted: Sat Mar 07, 2015 4:14 am
by OnoSendai
Ok, for variant A (random texture per instance) the code looks like this:

NUM_TEXTURES needs to be set to the number of textures in the shader.

Code: Select all

<material>
		<uid>4</uid>
		<name>ball</name>
		<phong>
			<diffuse_albedo>
				<shader>
						<shader>
    <![CDATA[
def eval(vec3 pos) vec3 :
  let 
    NUM_TEXTURES = 3
    tex_index = floorToInt(gridNoise(real(objectId())) * NUM_TEXTURES)
  in
    sample2DTextureVec3(tex_index, getTexCoords(0))
					]]></shader>

          <texture>
            <uv_set_index>0</uv_set_index>
            <path>indigo_logo.png</path>
            <exponent>2.2</exponent>
          </texture>

          <texture>
            <uv_set_index>0</uv_set_index>
            <path>tester.png</path>
            <exponent>2.2</exponent>
          </texture>

          <texture>
            <uv_set_index>0</uv_set_index>
            <path>blackrose_pattern.jpg</path>
            <exponent>2.2</exponent>
          </texture>

        </shader>
			</diffuse_albedo>
			<exponent>
					<constant>100</constant>
			</exponent>
			<layer>0</layer>
			<ior>1.2</ior>
			<nk_data></nk_data>
		</phong>
	</material>

Re: [REQ] Indigo instance color variation shader

Posted: Sat Mar 07, 2015 4:16 am
by OnoSendai
It occurs to me that a numShaderTextures() ISL function would be handy, will add that in. Won't be available for a while tho.

Re: [REQ] Indigo instance color variation shader

Posted: Sat Mar 07, 2015 4:43 am
by OnoSendai
Colour and gamma variation shader:

PIGS attached to play with.

Code: Select all

	<material>
		<uid>4</uid>
		<name>ball</name>
		<phong>
			<diffuse_albedo>
				<shader>
						<shader>
    <![CDATA[
def eval(vec3 pos) vec3 :
  let 
    c = sample2DTextureVec3(0, getTexCoords(0))
    id = real(objectId())
    
    gamma_var = paramGammaRandomAmount()
    shift_gamma = max(0.0, (1 - gamma_var) + gridNoise(id) * gamma_var * 2.0)
    
    colour_var = paramColorVariationAmount()
    colour_shift = (vec3(-0.5) + vec3(gridNoise(id), gridNoise(id + 34534), gridNoise(id + 9876465))) * (colour_var * 2.0)
  in
    vec3(pow(c.x, shift_gamma), pow(c.y, shift_gamma), pow(c.z, shift_gamma)) + colour_shift
					]]></shader>

          <param>
            <real>
              <name>GammaRandomAmount</name>
              <description>Amount of variation of texture gamma</description>
              <min>0</min>
              <max>2.0</max>
              <value>0.3</value>
            </real>
          </param>

          <param>
            <real>
              <name>ColorVariationAmount</name>
              <description>Amount of colour variation of texture</description>
              <min>0</min>
              <max>0.5</max>
              <value>0.04</value>
            </real>
          </param>


          <texture>
            <uv_set_index>0</uv_set_index>
            <path>ColorChecker_sRGB_from_Ref_CMYK.jpg</path>
            <exponent>2.2</exponent>
          </texture>
          

        </shader>
			</diffuse_albedo>
			<exponent>
					<constant>100</constant>
			</exponent>
			<layer>0</layer>
			<ior>1.2</ior>
			<nk_data></nk_data>
		</phong>
	</material>

Re: [REQ] Indigo instance color variation shader

Posted: Sat Mar 07, 2015 5:00 am
by zeitmeister
Wow Ono, thank you very much!!
Do you think it would be possible to Access the Shader Input fields 1:1 in the plugin exporters? That would save a lot of time.


Cheers, zeiti

Re: [REQ] Indigo instance color variation shader

Posted: Sat Mar 07, 2015 5:03 am
by OnoSendai
zeitmeister wrote:Wow Ono, thank you very much!!
Do you think it would be possible to Access the Shader Input fields 1:1 in the plugin exporters? That would save a lot of time.


Cheers, zeiti
what do you mean by the shader input fields?

Re: [REQ] Indigo instance color variation shader

Posted: Sat Mar 07, 2015 5:29 am
by zeitmeister
Indigo GUI:
Bildschirmfoto 2015-03-06 um 18.27.46.png
C4D GUI:
Bildschirmfoto 2015-03-06 um 18.27.31.png

[REQ] Indigo instance color variation shader

Posted: Sat Mar 07, 2015 6:19 am
by zeitmeister
Works like a charm, Ono!
Got to find out how to setup the Code for c4d...

Re: [REQ] Indigo instance color variation shader

Posted: Sat Mar 07, 2015 7:53 pm
by zeitmeister
Hey Ono,
would a combination work?
I managed to link color variation with your multiple texture setup, but I fail at the gamma_shift...

Re: [REQ] Indigo instance color variation shader

Posted: Sun Mar 08, 2015 1:58 am
by zeitmeister
Got it! :D
First three images ONLY ONE color texture. There are 8 different trees with 8 different alpha leaf blend materials; all accessing the main color changer material.
So this way I got to change/apply/setup the color variation shader ONE TIME, but get 8 different alpha leaf materials out of it.
Last picture using ONLY TWO textures, but color and gamma variation applied.
trees1.jpg
1 texture:
gamma variation + color variation
trees2.jpg
1 texture:
stronger gamma variation + color variation
trees3.jpg
closeup
screenshot_shader.jpg

Code: Select all

def eval(vec3 pos) vec3 :
	let

		NUM_TEXTURES = 2
		tex_index = floorToInt(gridNoise(real(objectId())) * NUM_TEXTURES)

		c = sample2DTextureVec3(tex_index, getTexCoords(0))
		id = real(objectId())

		gamma_var = paramGammaRandomAmount()
		shift_gamma = max(0.0, (1 - gamma_var) + gridNoise(id) * gamma_var * 2.0)

		colour_var = paramColorVariationAmount()
		colour_shift = (vec3(-0.5) + vec3(gridNoise(id), gridNoise(id + 34534), gridNoise(id + 9876465))) * (colour_var * 2.0)

	in
		vec3(pow(c.x, shift_gamma), pow(c.y, shift_gamma), pow(c.z, shift_gamma)) + colour_shift
trees4.jpg
2 textures:
gamma variation + color variation
leaf_color_variation.igm
(2.24 KiB) Downloaded 503 times

Re: [REQ] Indigo instance color variation shader

Posted: Sun Mar 08, 2015 2:00 am
by OnoSendai
nice, looking good!

Re: [REQ] Indigo instance color variation shader

Posted: Sun Mar 08, 2015 2:06 am
by zeitmeister
Thank you a lot!
The only knickknack is the fact that setting up the shader is not possible in the C4D exporter.
fused may have to invest work here, so that the C4D Indigo shader window offers the same possibilities as the Indigo standalone GUI shader window. Plus working and exporting things correctly.

BTW: Ono, does that shader "flicker" or sample everything new when rendering an animation?
And if yes, how can we interdict that?