ISL help
-
- Posts: 34
- Joined: Wed Jun 03, 2009 9:42 am
ISL help
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
I = Top Layer
M =Back Layer
- Attachments
-
- layer-mode-burn.png (4.65 KiB) Viewed 15245 times
Re: ISL help
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
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.
-
- Posts: 34
- Joined: Wed Jun 03, 2009 9:42 am
Re: ISL help
I mean tex1 (r1,g1,b1)/ tex2 (r2,g2,b2) = result (r1/r2,g1/g2,b1/b2)
Re: ISL help
okay, here we go:
another question of understanding: are the components assumed to be in the range of 0-255 for this function?
Code: Select all
def div(vec3 a, vec3 b) vec3: vec3(doti(a) / doti(b), dotj(a) / dotj(b), dotk(a) / dotk(b))
-
- Posts: 34
- Joined: Wed Jun 03, 2009 9:42 am
Re: ISL help
Yes, but it can be easily converted from 0-255 to 0-1. I'm testing...
-
- Posts: 34
- Joined: Wed Jun 03, 2009 9:42 am
Re: ISL help
Thanks Fused, it works!
Now I'm doing overlay, screen, etc
edit:: I think blending modes can be bundled into exporters.
Now I'm doing overlay, screen, etc
edit:: I think blending modes can be bundled into exporters.
Re: ISL help
Nice work chubaka,chubakueno wrote:Thanks Fused, it works!
Now I'm doing overlay, screen, etc
edit:: I think blending modes can be bundled into exporters.
I'm sure if you release your code you could speed up the Exporter integration

polygonmanufaktur.de
Re: ISL help
Oh yes!ZomB wrote:Nice work chubaka,chubakueno wrote:Thanks Fused, it works!
Now I'm doing overlay, screen, etc
edit:: I think blending modes can be bundled into exporters.
I'm sure if you release your code you could speed up the Exporter integration
If you post all your shader when youre done it will make its way into the ISL blend shader in cindigo

-
- Posts: 34
- Joined: Wed Jun 03, 2009 9:42 am
Re: ISL help
Overlay:
Normal:
Invert:(only the camouflage)
edit:Later I'll post the other blending modes
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
)
]]>
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
)
]]>
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)))
]]>
Re: ISL help
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:
in the other two shaders:
is the same thing as
and then passing that to the overlay/subtract function.
a few other optimizations/simplifications for your normal shader:
not tested tho 

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,
Code: Select all
sample2DTextureVec3(0,getTexCoords(0)) * 255.0
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
)

-
- Posts: 34
- Joined: Wed Jun 03, 2009 9:42 am
Re: ISL help
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.
Re: ISL help
easy fixchubakueno wrote:Yes, but you can't divide a vec3 with a real.

Code: Select all
div((v1 * 0.5) + (v2 * 0.5), vec3(255.0))
Code: Select all
def div(vec3 a, real b) vec3: vec3(doti(a) / b, dotj(a) / b, dotk(a) / b)
-
- Posts: 34
- Joined: Wed Jun 03, 2009 9:42 am
Re: ISL help
In general, you can't divide vec3's, only real vs real
Re: ISL help
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))
Who is online
Users browsing this forum: No registered users and 25 guests