ISL help

Feature requests, bug reports and related discussion
chubakueno
Posts: 34
Joined: Wed Jun 03, 2009 9:42 am

ISL help

Post by chubakueno » Tue Jan 05, 2010 12:58 pm

I'm working on a shader that blend towo textures with the "burn" equation. The problem is that I need to divide two vec3's and Indigo doesn't have that feature.¿Someone can help me?
I = Top Layer
M =Back Layer
Attachments
layer-mode-burn.png
layer-mode-burn.png (4.65 KiB) Viewed 15245 times

User avatar
fused
Developer
Posts: 3648
Joined: Fri Sep 22, 2006 7:19 am
Location: Berlin, Germany
3D Software: Cinema 4D

Re: ISL help

Post by fused » Tue Jan 05, 2010 1:28 pm

Hey, I really want to help you, but I'm not sure how the division should work.

Read this: http://www.mcasco.com/qa_vdq.html
In vectors there are two ways of multiplying, the dot product and the cross product.

[...]

dot division is not defined.

[...]

cross division is also undefined.

chubakueno
Posts: 34
Joined: Wed Jun 03, 2009 9:42 am

Re: ISL help

Post by chubakueno » Tue Jan 05, 2010 1:53 pm

I mean tex1 (r1,g1,b1)/ tex2 (r2,g2,b2) = result (r1/r2,g1/g2,b1/b2)

User avatar
fused
Developer
Posts: 3648
Joined: Fri Sep 22, 2006 7:19 am
Location: Berlin, Germany
3D Software: Cinema 4D

Re: ISL help

Post by fused » Tue Jan 05, 2010 2:06 pm

okay, here we go:

Code: Select all

def div(vec3 a, vec3 b) vec3: vec3(doti(a) / doti(b), dotj(a) / dotj(b), dotk(a) / dotk(b))
another question of understanding: are the components assumed to be in the range of 0-255 for this function?

chubakueno
Posts: 34
Joined: Wed Jun 03, 2009 9:42 am

Re: ISL help

Post by chubakueno » Tue Jan 05, 2010 2:28 pm

Yes, but it can be easily converted from 0-255 to 0-1. I'm testing...

chubakueno
Posts: 34
Joined: Wed Jun 03, 2009 9:42 am

Re: ISL help

Post by chubakueno » Wed Jan 06, 2010 3:05 am

Thanks Fused, it works!
Now I'm doing overlay, screen, etc
edit:: I think blending modes can be bundled into exporters.

User avatar
Zom-B
1st Place 100
Posts: 4701
Joined: Tue Jul 04, 2006 4:18 pm
Location: ´'`\_(ò_Ó)_/´'`
Contact:

Re: ISL help

Post by Zom-B » Wed Jan 06, 2010 5:15 am

chubakueno wrote:Thanks Fused, it works!
Now I'm doing overlay, screen, etc
edit:: I think blending modes can be bundled into exporters.
Nice work chubaka,

I'm sure if you release your code you could speed up the Exporter integration ;-)
polygonmanufaktur.de

User avatar
fused
Developer
Posts: 3648
Joined: Fri Sep 22, 2006 7:19 am
Location: Berlin, Germany
3D Software: Cinema 4D

Re: ISL help

Post by fused » Wed Jan 06, 2010 1:35 pm

ZomB wrote:
chubakueno wrote:Thanks Fused, it works!
Now I'm doing overlay, screen, etc
edit:: I think blending modes can be bundled into exporters.
Nice work chubaka,

I'm sure if you release your code you could speed up the Exporter integration ;-)
Oh yes!
If you post all your shader when youre done it will make its way into the ISL blend shader in cindigo :)

chubakueno
Posts: 34
Joined: Wed Jun 03, 2009 9:42 am

Re: ISL help

Post by chubakueno » Thu Jan 07, 2010 3:20 pm

Overlay:
isl_camo_overlay.jpg
isl_camo_overlay.jpg (96.6 KiB) Viewed 15065 times

Code: Select all

						<![CDATA[
					def overlay(real it1, real jt1, real kt1, real it2, real jt2, real kt2) vec3:
						vec3(div(mul(div(it1,255.0),add(it1,mul(div(mul(2.0,it2),255.0),sub(255.0,it1)))),255.0),
							div(mul(div(jt1,255.0),add(jt1,mul(div(mul(2.0,jt2),255.0),sub(255.0,jt1)))),255.0),
							div(mul(div(kt1,255.0),add(kt1,mul(div(mul(2.0,kt2),255.0),sub(255.0,kt1)))),255.0)
							)
					def eval(vec3 pos) vec3 :
						overlay(
						doti(sample2DTextureVec3(0,getTexCoords(0)))*255.0,
						dotj(sample2DTextureVec3(0,getTexCoords(0)))*255.0,
						dotk(sample2DTextureVec3(0,getTexCoords(0)))*255.0,
						doti(sample2DTextureVec3(1,getTexCoords(0)))*255.0,
						dotj(sample2DTextureVec3(1,getTexCoords(0)))*255.0,
						dotk(sample2DTextureVec3(1,getTexCoords(0)))*255.0
						)
						]]>
Normal:
isl_camo_normal.jpg
isl_camo_normal.jpg (105.78 KiB) Viewed 15065 times

Code: Select all

						<![CDATA[
					def substract(real it1, real jt1, real kt1, real it2, real jt2, real kt2) vec3:
						vec3(div(add(mul(it1,0.5),mul(it2,0.5)),255.0),
							div(add(mul(jt1,0.5),mul(jt2,0.5)),255.0),
							div(add(mul(kt1,0.5),mul(kt2,0.5)),255.0)
							)
					def eval(vec3 pos) vec3 :
						substract(
						doti(sample2DTextureVec3(0,getTexCoords(0)))*255.0,
						dotj(sample2DTextureVec3(0,getTexCoords(0)))*255.0,
						dotk(sample2DTextureVec3(0,getTexCoords(0)))*255.0,
						doti(sample2DTextureVec3(1,getTexCoords(0)))*255.0,
						dotj(sample2DTextureVec3(1,getTexCoords(0)))*255.0,
						dotk(sample2DTextureVec3(1,getTexCoords(0)))*255.0
						)
						]]>
Invert:(only the camouflage)
isl_camo_inv.jpg
isl_camo_inv.jpg (74.98 KiB) Viewed 15064 times

Code: Select all

						<![CDATA[
					def  substract(vec3 col1, vec3 colt) vec3:
						sub(col1,colt)
					def eval(vec3 pos) vec3 :
						substract((vec3(1.0)),
						sample2DTextureVec3(0,getTexCoords(0)))
						]]>
edit:Later I'll post the other blending modes

User avatar
fused
Developer
Posts: 3648
Joined: Fri Sep 22, 2006 7:19 am
Location: Berlin, Germany
3D Software: Cinema 4D

Re: ISL help

Post by fused » Thu Jan 07, 2010 3:52 pm

wow, pretty nice, a few nitpicks if you dont mind :)

in the invert shader, you dont really need a subtract() finction. i fact you dont even have to use the sub() function. just use operators:

Code: Select all

def eval(vec3 pos) vec3 :
                  vec3(1.0) - sample2DTextureVec3(0,getTexCoords(0))

in the other two shaders:

Code: Select all

doti(sample2DTextureVec3(0,getTexCoords(0)))*255.0,
dotj(sample2DTextureVec3(0,getTexCoords(0)))*255.0,
dotk(sample2DTextureVec3(0,getTexCoords(0)))*255.0,
is the same thing as

Code: Select all

sample2DTextureVec3(0,getTexCoords(0)) * 255.0
and then passing that to the overlay/subtract function.

a few other optimizations/simplifications for your normal shader:

Code: Select all

def div(vec3 a, vec3 b) vec3: vec3(doti(a) / doti(b), dotj(a) / dotj(b), dotk(a) / dotk(b))
def substract(vec3 v1, vec3 v2) vec3:
                     div((v1 * 0.5) + (v2 * 0.5), 255.0)
                     )
               def eval(vec3 pos) vec3 :
                  substract(
                  sample2DTextureVec3(0,getTexCoords(0))*255.0,
                  sample2DTextureVec3(1,getTexCoords(0))*255.0
                  )
not tested tho :)

chubakueno
Posts: 34
Joined: Wed Jun 03, 2009 9:42 am

Re: ISL help

Post by chubakueno » Thu Jan 07, 2010 4:05 pm

Yes, but you can't divide a vec3 with a real.edit:And thanks for the optimizations. :)
Last edited by chubakueno on Thu Jan 07, 2010 4:17 pm, edited 3 times in total.

User avatar
fused
Developer
Posts: 3648
Joined: Fri Sep 22, 2006 7:19 am
Location: Berlin, Germany
3D Software: Cinema 4D

Re: ISL help

Post by fused » Thu Jan 07, 2010 4:09 pm

chubakueno wrote:Yes, but you can't divide a vec3 with a real.
easy fix ;)

Code: Select all

div((v1 * 0.5) + (v2 * 0.5), vec3(255.0))
or:

Code: Select all

def div(vec3 a, real b) vec3: vec3(doti(a) / b, dotj(a) / b, dotk(a) / b)

chubakueno
Posts: 34
Joined: Wed Jun 03, 2009 9:42 am

Re: ISL help

Post by chubakueno » Thu Jan 07, 2010 4:48 pm

In general, you can't divide vec3's, only real vs real

User avatar
fused
Developer
Posts: 3648
Joined: Fri Sep 22, 2006 7:19 am
Location: Berlin, Germany
3D Software: Cinema 4D

Re: ISL help

Post by fused » Thu Jan 07, 2010 5:22 pm

sorry but that is what you asked for in the beginning. then I told you its not possible and you said what you meant. Then I wrote a function that does exactly that. And now you tell me its not possible.... hello?
fused wrote:

Code: Select all

def div(vec3 a, real b) vec3: vec3(doti(a) / b, dotj(a) / b, dotk(a) / b)
fused wrote:

Code: Select all

def div(vec3 a, vec3 b) vec3: vec3(doti(a) / doti(b), dotj(a) / dotj(b), dotk(a) / dotk(b))

Stinkie
Indigo 100
Posts: 616
Joined: Sat Oct 27, 2007 9:22 pm

Re: ISL help

Post by Stinkie » Thu Jan 07, 2010 9:22 pm

Neeeerd fiiiight! :twisted: :wink:

Post Reply
20 posts

Who is online

Users browsing this forum: No registered users and 25 guests