Shader tests

General questions about Indigo, the scene format, rendering etc...
User avatar
Kram1032
Posts: 6649
Joined: Tue Jan 23, 2007 3:55 am
Location: Austria near Vienna

Post by Kram1032 » Sat Sep 13, 2008 7:06 pm

CTZn wrote: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 :mrgreen:

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

Thanks fused :)
I more or less found it by accident when looking at a strange sphere-modification, I tried out :)


else return 0
Thanks !
Well, that's what I meant with either "if 0" or "if NaN", as x/0 produces a NaN

Though, I don't even know whether the language then puts out NaNs or even if you can use them....

In my Ti-92, it's undef (~NaN) but on the Wiki-article, it's meant to be defined....

Oh and the three comparisons are sufficient for what you'd need here... if you use two sines and give them a "gradient" via those three compares, and say

Code: Select all

if z>0
   then col_1
if z<0
   then col_2
if z=0
   then (col_1+col_2)/2
you could still control the tilesize the same way...

Code: Select all

z=sin(2pi*x/w_1)+sin(2pi*y/w_2)
Oh, and if you don't make your ws contant but change them to a function aswell, you could even get some alinear chessboard looks... There, you'd need to experiment though.... (and to be careful with w=0)

Thanks fused :)
I found that more or less by accident, when playing around with sgn and sin....[/code]

User avatar
CTZn
Posts: 7240
Joined: Thu Nov 16, 2006 4:34 pm
Location: Paris, France

Post by CTZn » Sat Sep 13, 2008 10:03 pm

Yes cheese nans, or cNaNs as you like. Look kram: coding is one thing, doing maths is another and I am the third. I can try coding, I won't try maths, sorry I didn't think before answering :)
obsolete asset

User avatar
Kram1032
Posts: 6649
Joined: Tue Jan 23, 2007 3:55 am
Location: Austria near Vienna

Post by Kram1032 » Sat Sep 13, 2008 10:28 pm

I actually wrote, you're correct and you can define (1D-) sgn with three simple tests... All the math you need is found in that short codebox.... The rest is just tests.

User avatar
Kram1032
Posts: 6649
Joined: Tue Jan 23, 2007 3:55 am
Location: Austria near Vienna

Post by Kram1032 » Sun Sep 14, 2008 1:04 am

With a lot more of math, you can do a probably interesting step fractalish thingy... (I actually dunno if it's indeed a fractal...)

I call it "circular rounding"

standard rounding works like this:

Code: Select all

floor(x+0,5) = rounded to 0 digits
by changing the weight-value (if I can call it like that) "0,5" you can affect the probability of rounding up or down....

further, you can enhance the precession, or reduce it as you want:

Code: Select all

floor(x/5+0,5)*5 = rounded to 0 or 5 at the end
floor(2*x+0,5)/2= rounded to halves (,5)

floor(x*10^a+0,5)/10^a = rounded to a digits (a usually can be an Integer)
Now, you actually can extend that precession-choice so that you get "fractional digits", by allowing any real number for a

next thing, you can do, is to change the base... The 10^a actually comes from the fact that any number we use is built like sigma(k*10^n) where 10 is the base, k is a natural number between 0 and 9 and n is any integer. If you'd use a binary number, you could also use a binary base

Code: Select all

floor(x*2^a+0,5)/2^a
Or you can use a "wrong" base to get other results...

So, now we have

Code: Select all

floor(x*b^a+0,5)/b^a
Let's go back to the 0,5:

floor(x) would reduce any value a,bcdefg...... to a
to get the rounding for up and down correct, you need to add 0,5:

Code: Select all

floor(1) =1
floor(1,3) =1
floor(1,7) =1
but

Code: Select all

floor(1+0,5) = floor(1,5) = 1
floor(1,3+0,5) = floor(1,8) = 1
floor(1,7+0,5) = floor(2,2) = 2
setting that value to 0 means, you always round down
setting it to 1 means, you always round up (with the exception of having an integer already, where it rounds to the next integer:

Code: Select all

floor(1+1) = floor(2) = 2
- to get that correct, you'd need "biggest possible x < 1")

Now, there's a problem:

Code: Select all

floor(-0,5+0,5)=floor(0)=0
- the result actually should be -1!
To solve this, we need to do this:

Code: Select all

floor(abs(-1)+0,5)*sgn(-1) = floor(1,5)*-1 = -floor(1,5) = 1
Next step of extension is, to do this in complex values... Here, the circularness of the formula starts:

Currently we have:

Code: Select all

floor(abs(x)*b^a+p)*sgn(x)/b^a
To get it to a higher dimension R², let's add a second variable (b, a and p usually will be constant but it you make them variable too, you might get really interesting results by letting each variable control a different thing... on cost of rendering speed, probably)

Let's add an y

Code: Select all

floor(abs(x+y)*b^a+p)*((x+y)/sqrt(x²+y²))/b^a
what you get is sort of a chairhouse... (or a very odd checker-board, if you put it out like that.... you just'd need to kinda check for a jump in the line... "if jump then change col"

I actually tried that (to a very small extend) with complex values:

Code: Select all

floor(abs(x+yi)*(b+di)^(a+ci)+(p+qi))*((x+yi)/sqrt(x²+y²))/(b+di)^(a+ci)=r+si

sqrt(p²+q²)<=1
10D! - if you( coul)'d look at the WHOLE object, you'd probably see the most confusing staircase, ever.

User avatar
dougal2
Developer
Posts: 2532
Joined: Wed Nov 15, 2006 8:17 am
Location: South London

Post by dougal2 » Sun Sep 14, 2008 4:11 am

c'mon then Kram, lets see a render of this !!

User avatar
Kram1032
Posts: 6649
Joined: Tue Jan 23, 2007 3:55 am
Location: Austria near Vienna

Post by Kram1032 » Sun Sep 14, 2008 4:39 am

Would be happy to do so, but I think, I can't....

User avatar
F.ip2
Posts: 160
Joined: Thu Aug 10, 2006 11:05 am

Post by F.ip2 » Sun Sep 14, 2008 7:22 am

Anisotropic reflections has to be done with a bump mapping trick?

there is no UV exponent setting ?
--
C l a a s E i c k e K u h n e n
Artist : Designer : Educator

Assistant Professor Industrial Design
Kendall College of Art and Design
of Ferris State University

Big Fan
Posts: 745
Joined: Tue Oct 17, 2006 9:37 am
Location: Nelson NZ

Post by Big Fan » Sun Sep 14, 2008 9:18 am

yes the 'anisotropic' shader on p6 needs uv's

if you are experimenting with blendigo SW 1.1.10
unwrap as usual and select the green button next to bump to enable it for export ,hit the 'populate button'
dont load a map picture for bump
press the 'use bump shader' button and select from the shader options

most likely the UI for this isnt as intuitive as it could be and needs some refining :wink:

HTH
BF

User avatar
cpfresh
Posts: 501
Joined: Thu Jun 14, 2007 12:20 pm
Location: California, USA
Contact:

Post by cpfresh » Mon Sep 15, 2008 1:09 pm

why does the error, "Couldn't find function eval :" occur and how can it be avoided? i've got an eval there so what does it really mean? what am i missing? :/

Big Fan
Posts: 745
Joined: Tue Oct 17, 2006 9:37 am
Location: Nelson NZ

Post by Big Fan » Mon Sep 15, 2008 2:20 pm

ah I can answer that

if you are using ono's first code sample from p6 as cut and paste there is a mis-code in there

make it like this instead

def eval() real :")

( thanks to ono for the fix)

User avatar
cpfresh
Posts: 501
Joined: Thu Jun 14, 2007 12:20 pm
Location: California, USA
Contact:

Post by cpfresh » Mon Sep 15, 2008 4:02 pm

nah i wasnt using that little code snippit. so any other ideas? :0

User avatar
Kram1032
Posts: 6649
Joined: Tue Jan 23, 2007 3:55 am
Location: Austria near Vienna

Post by Kram1032 » Tue Sep 16, 2008 2:19 am

Indigo Version and failing code, pls? ^^

User avatar
cpfresh
Posts: 501
Joined: Thu Jun 14, 2007 12:20 pm
Location: California, USA
Contact:

Post by cpfresh » Tue Sep 16, 2008 5:42 am

hiya kram, i dont jave the code with me at the moment, but i'll paste it in once i get home.

i'm currently using Indigo 1.1.10...stay tuned.

*edit*
ok so i just tried to rewrite the code over my lunch break and now it just kills indigo without any error message at all D:

please peruse my code:

Code: Select all

def eval(vec3 pos) vec3:
vec3(
	if(
		gte(
			mod(
				doti(
					getTexCoords(0)
				),128.0
			),
			div(
				125.0,128.0
			)
		),0.0,1.0
	),
	if(
		gte(
			mod(
				dotj(
					getTexCoords(0)
				),64.0
			),
			div(
				61.0,64.0
			)
		),0.0,1.0
	),0.0
)
what i'm trying to do is create a grid which will eventually become a brick pattern and eventually require a scaling modifier. right now it should be just a grid with every course the same (no alternating offset.)

thanks for any comments and assistance. :)

User avatar
Hans
Posts: 14
Joined: Thu Jan 11, 2007 3:58 am
Location: Japan
Contact:

Post by Hans » Mon Sep 22, 2008 1:01 am

I read some posts where several people discussed anisotropic effect in this thread. Someone suggested a good way to fake it by using a bump map and I took a test with indigo 1.1.9.
The effect for anisotropy can be seen in the following image but it looks less realistic :(

Image

The following image shows how the bump map was put on the planes.

Image


It's all a fake, but the three parameters, IOR, Exponent, and B in Bump map in Blendigo 1.1.7, affect anisotropy well and you can change the looks easily :D. Getting IOR high will make the reflection bright, getting Exponent high will make the reflection thin, and getting B high will make anisotropic effect strong.

User avatar
Kram1032
Posts: 6649
Joined: Tue Jan 23, 2007 3:55 am
Location: Austria near Vienna

Post by Kram1032 » Mon Sep 22, 2008 1:30 am

If you do the same with shaders (should be pretty simple sine shaders, like

Code: Select all

(sin(2*pi*x/w)+1)/2
), you can use far smaller grooves, resulting in more realistic pics ;)

Code: Select all

w=groove width. So, use VERY small w
if you multiply with w instead, it's like frequency, meaning "w grooves per (probably) meter" - in that case, w should be big
To get a circular shader, you need to use two variables instead of one:

Code: Select all

sin(2*pi*sqrt(x²+y²)/w)

Post Reply
223 posts

Who is online

Users browsing this forum: No registered users and 3 guests