yesDeus wrote:That was cool1.1.9?

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>
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>
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) ?
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
}
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)
Code: Select all
sgn(x+y+....+?) = sqrt(x²+y²+...+?²)(x+y+...+?)/(x*y*...*?)
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) /2
Code: Select all
x, y and z are real variables
w_1 and w_2 are constants
pi == pi ( d'oh )
Code: Select all
if x < 0
return -1
if x > 0
return 1
else return 0
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>
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>
Users browsing this forum: No registered users and 5 guests