Page 1 of 2
ISL help
Posted: Tue Jan 05, 2010 12:58 pm
by chubakueno
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
Re: ISL help
Posted: Tue Jan 05, 2010 1:28 pm
by fused
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.
Re: ISL help
Posted: Tue Jan 05, 2010 1:53 pm
by chubakueno
I mean tex1 (r1,g1,b1)/ tex2 (r2,g2,b2) = result (r1/r2,g1/g2,b1/b2)
Re: ISL help
Posted: Tue Jan 05, 2010 2:06 pm
by fused
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?
Re: ISL help
Posted: Tue Jan 05, 2010 2:28 pm
by chubakueno
Yes, but it can be easily converted from 0-255 to 0-1. I'm testing...
Re: ISL help
Posted: Wed Jan 06, 2010 3:05 am
by chubakueno
Thanks Fused, it works!
Now I'm doing overlay, screen, etc
edit:: I think blending modes can be bundled into exporters.
Re: ISL help
Posted: Wed Jan 06, 2010 5:15 am
by Zom-B
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

Re: ISL help
Posted: Wed Jan 06, 2010 1:35 pm
by fused
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

Re: ISL help
Posted: Thu Jan 07, 2010 3:20 pm
by chubakueno
Overlay:

- isl_camo_overlay.jpg (96.6 KiB) Viewed 16378 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 (105.78 KiB) Viewed 16378 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 (74.98 KiB) Viewed 16377 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
Re: ISL help
Posted: Thu Jan 07, 2010 3:52 pm
by fused
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

Re: ISL help
Posted: Thu Jan 07, 2010 4:05 pm
by chubakueno
Yes, but you can't divide a vec3 with a real.edit:And thanks for the optimizations.

Re: ISL help
Posted: Thu Jan 07, 2010 4:09 pm
by fused
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)
Re: ISL help
Posted: Thu Jan 07, 2010 4:48 pm
by chubakueno
In general, you can't divide vec3's, only real vs real
Re: ISL help
Posted: Thu Jan 07, 2010 5:22 pm
by fused
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))
Re: ISL help
Posted: Thu Jan 07, 2010 9:22 pm
by Stinkie
Neeeerd fiiiight!
