yesDeus wrote:That was cool1.1.9?
Shader tests
im not bored yet 
more displacement:
more displacement:
Code: Select all
<material>
<name>shader</name>
<diffuse>
<albedo>
<shader>
<shader>
<![CDATA[
def colorCalc(real x) vec3 :
vec3(
# compute color mix
# color1 \/ color2 \/
add(mul(0.75,x),mul(sub(1.0,x),0.00)),
add(mul(0.52,x),mul(sub(1.0,x),0.21)),
add(mul(0.00,x),mul(sub(1.0,x),0.88))
)
def eval(vec3 pos) vec3 :
colorCalc(
div(add(sin(mul(div(mod(doti(getTexCoords(0)),0.333333),0.333333),6.2831852)),
sin(mul(div(mod(dotj(getTexCoords(0)),0.333333),0.333333),6.2831852))),2.0)
)
]]>
</shader>
</shader>
</albedo>
<displacement>
<shader>
<shader>
<![CDATA[
# sinus waves displacment U
def eval() real :
add(
mul(sin(mul(div(mod(doti(getTexCoords(0)),0.333333),0.333333),6.2831852)),7.5),
mul(sin(mul(div(mod(dotj(getTexCoords(0)),0.333333),0.333333),6.2831852)),7.5)
)
]]>
</shader>
</shader>
</displacement>
</diffuse>
</material>- Attachments
-
- im1218632453.png (533.13 KiB) Viewed 3946 times
- Kosmokrator
- Posts: 1141
- Joined: Sat Jul 29, 2006 11:52 am
- Location: Greece-Athens
heres a the checkerboard shader ive been planing to do for a long time.
with the shder lang updates in 1.1.10 its finally possible.
with the shder lang updates in 1.1.10 its finally possible.
Code: Select all
<albedo>
<shader>
<shader>
<![CDATA[
# checkerboard
def eval(vec3 pos) vec3 :
vec3(
if(
eq(
add( #\/ this controls the tiles
if(gt(mod(mul(doti(getTexCoords(0)),2.0),2.0),1.0),1,0),
if(gt(mod(mul(dotj(getTexCoords(0)),2.0),2.0),1.0),1,0)
),1
),0.85,0.025 # these values control the color
)
)
]]>
</shader>
</shader>
</albedo>- Attachments
-
- im1221046925.jpg (43.17 KiB) Viewed 3659 times
Thanks fused, it's good to see advanced Indigo features being used !
I was wondering if there was existing an alternate way for scripting this checker effect, just another way to lay the code out ? Or does this language, as "functional", have only one way to be written (concatenating operations) ?
Subsidiary question: could one translate this checker code in another (readable) language, eventually pseudocode, so we can learn by comparison ?
Thanks, none of the above is mandatory.
I was wondering if there was existing an alternate way for scripting this checker effect, just another way to lay the code out ? Or does this language, as "functional", have only one way to be written (concatenating operations) ?
Subsidiary question: could one translate this checker code in another (readable) language, eventually pseudocode, so we can learn by comparison ?
Thanks, none of the above is mandatory.
obsolete asset
im sure there are easier ways, ono said something about doing it with xor and floor, but this isnt in the shader language yet.CTZn wrote:Thanks fused, it's good to see advanced Indigo features being used !
I was wondering if there was existing an alternate way for scripting this checker effect, just another way to lay the code out ? Or does this language, as "functional", have only one way to be written (concatenating operations) ?
he also said what i did is a bit like xor.
i think i can translate it to some pseudo code for youCTZn wrote:Subsidiary question: could one translate this checker code in another (readable) language, eventually pseudocode, so we can learn by comparison ?
Thanks, none of the above is mandatory.
Code: Select all
function eval returns vec3
{
integer x
integer color_u, color_v
float tiles = 2.0
if modulo(texture_coordinate_u * tiles, 2.0) > 1.0 color_u = 1
else color_u = 0
if modulo(texture_coordinate_v * tiles, 2.0) > 1.0 color_v = 1
else color_v = 0
x = color_u + color_v
if x equal 1 return Vec3(0.0) //black_color
else return Vec3(1.0) //white_color
}as you can see black fields always have the values 0 or 2 and only white fileds can have the value 1.
and im sure there are better ways to do it or to explain it
- Attachments
-
- tcheckerboard.jpg (17.09 KiB) Viewed 3548 times
Code: Select all
z = sgn( sin(x)+sin(y) )
if z == -1 col = col 1
if z == 1 col = col 2
if z == NAN or 0 (depending on how sgn is defined...) col = (col1 + col2)/2)In case of higher dimensions (or complex numbers or such),
Code: Select all
sgn(x+y+....+?) = sqrt(x²+y²+...+?²)(x+y+...+?)/(x*y*...*?)http://en.wikipedia.org/wiki/Sign_function
I've no idea how fast that'd be, though....
to control the tile-width, you can modify the formula...
sin(x) has a wavelength of 2pi
to get a wavelength of 1, you need to use sin(2pi*x)
To get a wavelenght w, you need to use sin(2pi*x/w)
so the total formula is:
Code: Select all
z=sgn( sin(2pi*x/w_1) + sin(2pi*y/w_2) )
if z = -1 then col = col_1
if z = 1 then col = col_2
if z = NAN or 0 then col = (col_1 + col_2) /2Code: Select all
x, y and z are real variables
w_1 and w_2 are constants
pi == pi ( d'oh )Woaow fused, that's a bit more than I expected, thanks a lot ! Now I understand the logic, I am able to run through (hopefully). The picture helps a lot 
Kram: I don't understand your formula yet, but I bet fused way is faster since it involves less calculations but compares more (faster). A friend of mine called when I was reading your post, and he told me that signum was not reliable since it can't manage x = 0 (wich should not happen when dealing with a checker, but with computers you never know), he proposed:
Thanks !
Kram: I don't understand your formula yet, but I bet fused way is faster since it involves less calculations but compares more (faster). A friend of mine called when I was reading your post, and he told me that signum was not reliable since it can't manage x = 0 (wich should not happen when dealing with a checker, but with computers you never know), he proposed:
Code: Select all
if x < 0
return -1
if x > 0
return 1
else return 0obsolete asset
- PureSpider
- Posts: 1459
- Joined: Tue Apr 08, 2008 9:37 am
- Location: Karlsruhe, BW, Germany
- Contact:
watch out for the "this controls the tiles"fused wrote:Code: Select all
<albedo> <shader> <shader> <![CDATA[ # checkerboard def eval(vec3 pos) vec3 : vec3( if( eq( add( #\/ this controls the tiles if(gt(mod(mul(doti(getTexCoords(0)),2.0),2.0),1.0),1,0), if(gt(mod(mul(dotj(getTexCoords(0)),2.0),2.0),1.0),1,0) ),1 ),0.85,0.025 # these values control the color ) ) ]]> </shader> </shader> </albedo>
@cpfresh: purespider is right
but maybe text size is playing tricks on you, so i added a better formatted version for you.
basically i calculate the color in u and v direction by multiplying the u/v value with the value for tilesu/tilesv. then i do a modulo of the value and 2 to get it in the range of 0-1.9999999. >1 is 1 and <1 is 0. at the end i add the resulting values for u and v together and if this value is 1 the texture at this position is white, else its black (have a look at the picture).
again, this is no perfect solution. i had this idea at work (so i was half absent minded
). ono posted a better way to do it on irc today. but it will only work in future versions (due to floor).
@CTZn: np
@Kram: nice solution, pretty clever
(cleverer than mine
)
basically i calculate the color in u and v direction by multiplying the u/v value with the value for tilesu/tilesv. then i do a modulo of the value and 2 to get it in the range of 0-1.9999999. >1 is 1 and <1 is 0. at the end i add the resulting values for u and v together and if this value is 1 the texture at this position is white, else its black (have a look at the picture).
again, this is no perfect solution. i had this idea at work (so i was half absent minded
@CTZn: np
@Kram: nice solution, pretty clever
Code: Select all
<albedo>
<shader>
<shader>
<![CDATA[
# checkerboard
def eval(vec3 pos) vec3 :
vec3(
if(
eq(
add(
if(gt(mod(mul(
doti(
getTexCoords(0)),
2.0 # this value controls the tiles in u direction
),2.0),1.0),1,0),
if(gt(mod(mul(
dotj(
getTexCoords(0)),
2.0 # this value controls the tiles in v direction
),2.0),1.0),1,0)
),1
),0.85,0.025 # these values control the color
)
)
]]>
</shader>
</shader>
</albedo>Who is online
Users browsing this forum: Ahrefs [Bot] and 104 guests


