Page 1 of 2

random rotation texture tiles

Posted: Tue Jan 08, 2013 11:35 pm
by CADMonkey
Is there a function in skindigo to randomly rotate a texture at point of render?

I'm working on a large tiled floor area. They use the same patterned tile throughout but they are laid with a random rotation.

I can aproxuimate the effect by ganging up several tiles in a texture image but when I do a high arial view you can see the repeat and the file is obviously just massive.

Is there a function to do this within Indigo? Is it a Shader function?

Also I assume truely random would be a bad idea? Would that mean the tiles could change orientation from render to render?

Below is a diagram of the effect I am looking to achieve: Tiles with any rotation just repeating across a floor

Re: random rotation texture tiles

Posted: Tue Jan 08, 2013 11:56 pm
by Zom-B
Adding a functionality to define X textures to use from in the tiling and I'm happy too :)

Re: random rotation texture tiles

Posted: Wed Jan 09, 2013 12:08 am
by OnoSendai
Should be pretty easy to do in ISL at least :)

Re: random rotation texture tiles

Posted: Wed Jan 09, 2013 12:22 am
by StompinTom
OnoSendai wrote:Should be pretty easy to do in ISL at least :)
Ah that'd be amazing for tiles / floorboards / bricks. A kind of MultiTexture for Indigo.

Re: random rotation texture tiles

Posted: Wed Jan 09, 2013 1:18 am
by OnoSendai
Here's a first crack at it.
Randomly selects from 3 textures, with a random orientation for each texture.

Shader looks like so (may have bugs!)

Code: Select all

 def rotate(real r, vec2 st) vec2:
              let 
                s = x(st)
                t = y(st)  
              in
                if(r < 0.5,
                  if(r < 0.25,
                      vec2(s, t),
                      vec2(t, -s)
                  ),
                  if(r < 0.75,
                    vec2(-s, -t),
                    vec2(-t, s)
                  )
                )
              
            def eval(vec3 pos) vec3 :
              let
                uv = getTexCoords(0)
                st = rotate(gridNoise(uv), uv)
                NUM_TEXTURES = 3
                tex_index = floorToInt(gridNoise(vec2(x(uv) + 45655.0, y(uv) + 3257.0)) * real(NUM_TEXTURES))
              in
                sample2DTextureVec3(tex_index, st)

Re: random rotation texture tiles

Posted: Wed Jan 09, 2013 1:57 am
by Zom-B
Damn that was quick :D

Will have a deeper look into it soon!
Thanks a lot Ono!!!

Re: random rotation texture tiles

Posted: Wed Jan 09, 2013 3:15 am
by CADMonkey
Amazing!

Thank you so Much

Re: random rotation texture tiles

Posted: Wed Jan 09, 2013 3:48 am
by snorky
:?: and mirroring function?

Re: random rotation texture tiles

Posted: Wed Jan 09, 2013 6:37 am
by OnoSendai
snorky wrote::?: and mirroring function?
Mirroring is easy to add if needed.

Re: random rotation texture tiles

Posted: Wed Jan 09, 2013 12:24 pm
by StompinTom
OnoSendai wrote:Here's a first crack at it.
Randomly selects from 3 textures, with a random orientation for each texture.

Shader looks like so (may have bugs!)

Code: Select all

 def rotate(real r, vec2 st) vec2:
              let 
                s = x(st)
                t = y(st)  
              in
                if(r < 0.5,
                  if(r < 0.25,
                      vec2(s, t),
                      vec2(t, -s)
                  ),
                  if(r < 0.75,
                    vec2(-s, -t),
                    vec2(-t, s)
                  )
                )
              
            def eval(vec3 pos) vec3 :
              let
                uv = getTexCoords(0)
                st = rotate(gridNoise(uv), uv)
                NUM_TEXTURES = 3
                tex_index = floorToInt(gridNoise(vec2(x(uv) + 45655.0, y(uv) + 3257.0)) * real(NUM_TEXTURES))
              in
                sample2DTextureVec3(tex_index, st)
Awesome!

Re: random rotation texture tiles

Posted: Thu Jan 10, 2013 6:23 am
by CADMonkey
Hi Folks...

Thanks so much what the ffort above... It does exactly what I would like to do.

However:


When I try to use the shader above I just get a black face... I assume its becuase it can't find the texures?


I'm using sketchup and relatively new to Indigo. Could someone give me a clue as how to apply several textures to a material please.

Re: random rotation texture tiles

Posted: Thu Jan 10, 2013 6:41 am
by Zom-B
The code above isn't the full shader to copy & paste that way!
There are also texture definitions inside the igs file.

best to open the pigs above in Indigo, pick the material and save it as a separate file to analyze it.
Afaik Exporters aren't capable of importing/exporting multiple textures atm!

Ono, is there a Exporter friendly way of defining the textures directly in the Shader?

Code: Select all

<scenedata>
	<material>
		<uid>5</uid>
		<name>mat1</name>
		<diffuse>
			<texture>
				<path>C:\Users\Zom-B\AppData\Local\Temp\indigo_temp_dir\indigo_temp_dir_1357756186\PACKED_1_ColorChecker_sRGB_from_Ref_lzw.tiff</path>
				<a>-0</a>
				<b>1</b>
				<c>-0</c>
				<uv_set_index>0</uv_set_index>
				<exponent>2.2</exponent>
				<tex_coord_generation>
					<uv>
						<matrix>1 0 0 1</matrix>
						<translation>0 -0</translation>
					</uv>
				</tex_coord_generation>
				<smooth>false</smooth>
			</texture>
			<texture>
				<path>C:\Users\Zom-B\AppData\Local\Temp\indigo_temp_dir\indigo_temp_dir_1357756186\PACKED_2_indigo_logo.png</path>
				<a>-0</a>
				<b>1</b>
				<c>-0</c>
				<uv_set_index>0</uv_set_index>
				<exponent>2.2</exponent>
				<tex_coord_generation>
					<uv>
						<matrix>1 0 0 1</matrix>
						<translation>0 -0</translation>
					</uv>
				</tex_coord_generation>
				<smooth>false</smooth>
			</texture>
			<texture>
				<path>C:\Users\Zom-B\AppData\Local\Temp\indigo_temp_dir\indigo_temp_dir_1357756186\PACKED_3_UV_mapper.jpg</path>
				<a>-0</a>
				<b>1</b>
				<c>-0</c>
				<uv_set_index>0</uv_set_index>
				<exponent>2.2</exponent>
				<tex_coord_generation>
					<uv>
						<matrix>1 0 0 1</matrix>
						<translation>0 -0</translation>
					</uv>
				</tex_coord_generation>
				<smooth>false</smooth>
			</texture>
			<albedo>
				<shader>
						<shader><![CDATA[  
            
            def rotate(real r, vec2 st) vec2:
              let 
                s = x(st)
                t = y(st)  
              in
                if(r < 0.5,
                  if(r < 0.25,
                      vec2(s, t),
                      vec2(t, -s)
                  ),
                  if(r < 0.75,
                    vec2(-s, -t),
                    vec2(-t, s)
                  )
                )
              
            def eval(vec3 pos) vec3 :
              let
                uv = getTexCoords(0)
                st = rotate(gridNoise(uv), uv)
                NUM_TEXTURES = 3
                tex_index = floorToInt(gridNoise(vec2(x(uv) + 45655.0, y(uv) + 3257.0)) * real(NUM_TEXTURES))
              in
                sample2DTextureVec3(tex_index, st)
            ]]></shader>
				</shader>
			</albedo>
			<random_triangle_colours>false</random_triangle_colours>
			<layer>0</layer>
		</diffuse>
	</material>
</scenedata>

Re: random rotation texture tiles

Posted: Thu Jan 10, 2013 6:42 am
by OnoSendai
Zom-B wrote: Ono, is there a Exporter friendly way of defining the textures directly in the Shader?
Not currently.

Re: random rotation texture tiles

Posted: Thu Jan 10, 2013 6:48 am
by Zom-B
Setting some Variables that define maps and use them later on in the Shader would be useful.
Keeping stuff in the Shader would raise compatibility to Exporters, and ISL coding easier for n00bs like me ^^

Re: random rotation texture tiles

Posted: Mon May 27, 2013 6:35 am
by OnoSendai
I uploaded a material using this random texture selection approach:
http://www.indigorenderer.com/materials/materials/1182

You can replace the textures used with your own textures to make it work for ceramic tiles etc..