- AVS Troubleshooting
- Can´t get that loop to work
Archive: Can´t get that loop to work
ASD5A
18th April 2005 09:59 UTC
Can´t get that loop to work
i need help, please look through this code:
loop(32,exec2(assign(sb,if(above(gmegabuf(ct+2),z3),1,if(above,(r0/(1+gmegabuf(ct3+2)/dst),sqrt(sqr(x-gmegabuf(ct3))+sqr(y-gmegabuf(ct3+1)))),0,1))),assign(ct3,ct3+3)));
this loop should assign sb 0 if the current point lies
behind(z3 value)and near any buffered points.
This code should be used to find invisible points.
if you find any mistakes in the code feel free to post
the corrected code or if you have a faster method to
find invisible points please post.
Jaak
18th April 2005 12:39 UTC
second if is fucked
was that really worth posting?
ASD5A
18th April 2005 13:08 UTC
i really don´t see the point
please post a corrected code
Jaak
18th April 2005 13:35 UTC
if(above,(r0/(1+gmegabuf(ct3+2)/dst), ...
ASD5A
18th April 2005 13:38 UTC
oh a veery stupid mistake thanx jaak
PAK-9
18th April 2005 13:42 UTC
Just a hint: Noone can be bothered to read that code because its all in one big block, people will be much more likely to help if you format it better, for example:
loop(32,
exec2(
assign(
sb
,
if(above(gmegabuf(ct+2),z3),
1
,
if(
above,( //extra comma
r0/(1+gmegabuf(ct3+2)/dst)
,
sqrt(
sqr(
x-gmegabuf(ct3)
)
+sqr(
y-gmegabuf(ct3+1)
)
)
)
,
0
,
1
)
)
)
,
assign(
ct3
,
ct3+3
)
)
);
I know it looks long but its a lot easier to read
ASD5A
18th April 2005 17:28 UTC
thanx pak-9
but i have a more complicated (coding) problem in this preset.
even with the mistake removed that code doesn´t filter out
normally invisible points.
But i have totally no clue why.
there are now two ways to go for me :
1.hoping somebody gives me a working code or
2.i figure out how to sort fast 4096 points.
I´ll start developing a sorting engine.
PAK-9
18th April 2005 18:16 UTC
I think its unlikely you need to sort the points in your preset.
If you explain the problem fully and in context it would help
ASD5A
18th April 2005 18:27 UTC
i assume u downloaded the preset above corrected the silly mistake.
ok..
in certain angles of torus u see points of the inner side of the torus which should be invisible.
there two way get rid of these points:
1. sort all the points by z3 value
2. filter them with a very simple raytrace.
my code above should be the 2. way but it filters only a little circle out.
gmegabuf(ct3) is the x value of an simple geometrical model
used for the raytrace.
gmegabuf(ct3+1) y value.
gmegabuf(ct3+2) z3 value.
ASD5A
18th April 2005 18:28 UTC
probably it could be the fault of my laptop
3ghz 12fps at this preset. how fast is yours?
PAK-9
18th April 2005 20:09 UTC
Oh sorry I didnt see that you posted the preset already, I'll check it when I get home.
preliminarily (having not seen the preset) you just have a culling/occlusion problem. If you store/calculate the normal at each point on the torus you can do a simple check to see if the vertex is facing away from the camera. Do a dot product with the camera vector and check if the angle is above a certain value, well, zero I guess (I cant really remember this all off the top of my head)
torus is a bit of a bastard because you cant do any nice quick hacks that I can think of.... hmm, maybe splitting the torus into rings. Nah, I think a hack would be more complicated than just doing it right.
Jaak
18th April 2005 22:19 UTC
Pak, simple normal calculation and bf culling isn`t enough for torus
http://www.deviantart.com/deviation/6457036/
really old preset and unfinished preset...
it`s with little help from coned, to correct the clipping problem. It is quite nasty hack ya know.
Torus can get intersected in 4 places if you trace line from eye through it, this means that regular bf culling does not work, if you do not want to use use max. blending... which you could actually live with in your example preset.
Anyways, to correct the torus clipping problem, which i assume you want to do, you can use
a) expencive raytracing hack
b) relatevely fast and really nasty hack described below
c) even slower way to sort the verices and do some dark magic *g*
as for b. the one you can see from example preset:
basically you have to split torus in 2, front and back and then:
1. draw back normally
2. draw front so it overlays not required part of back (try to disable 3rd scope in my preset)
3. draw front normally
as for you, if you are not going to advance that preset from its current state, i reccomend you just to use simple depth shading in addition to lighting shading to be able to use max blending so you won`t have clipping problems.
[edit]
Actually, I don`t know, I am really really sleepy right now. It would be best if you tolf us exactly what are you trying to do, because using the "correct" and "perfect" method with avs is usually the stupidest way of doing something, just remember that :p
As a side note... This preset is just a tech demo. I had a much better and similar stuff cooking for a actual preset, but I`m not working on it anymore...
jheriko
19th April 2005 01:50 UTC
actually simple bf culling is enough for the torus if you render four superscopes. this is done by rendering the back facing back half, front facing back half then back facing front half and finally front facing front half. This can be done with a simple z check and normal check and using all four combinations.
anything based totally on circles can usually be done correctly with no sorting or hax. this means shapes like torii, spheres and cylinders and arrangements like having objects on the points of a regular polygon etc...
Jaak
19th April 2005 06:43 UTC
...and which is what i am doing in the preset
...basically
ASD5A
19th April 2005 07:03 UTC
pak that what you suggest is already in the preset.
got an idea : using my current scope as feeder scope.
split the points into +z and -z and draw the nearer points later. that is actually what jheriko did suggest but i will leave out the backfacing halfes.
I´ll report if that works.
PAK-9
19th April 2005 12:55 UTC
Originally posted by jheriko
actually simple bf culling is enough for the torus if you render four superscopes. this is done by rendering the back facing back half, front facing back half then back facing front half and finally front facing front half. This can be done with a simple z check and normal check and using all four combinations.
anything based totally on circles can usually be done correctly with no sorting or hax. this means shapes like torii, spheres and cylinders and arrangements like having objects on the points of a regular polygon etc...
I dont see how this would work, because you cant split the torus into 4 in the same way for all angles. If you imagine looking at the tours from the side and splitting it into 4 as you suggest, then rotate it 90 degrees so you are looking at it from the top (i.e. it looks like a fat circle) the four pieces are the wrong shape to represent the front and back of the torus from the camera. You would have to reshape the 4 pieces depending on the rotation, which is a pretty nasty way to approach the problem imo. In fact rereading Jaak's post he is suggesting something similar where the torus is split into 2, where reshaping the two pieces is still necessary because the 'front' and 'back' different shapes from different angles.
I'm surprised the standard bf culling method doesnt work to be honest, because I would think you would compare the normal of the vertex on the torus with a camera ray, but not literaly fire a ray from the camera, just consider a vector which is 0 degrees from the camera direction. Then dot product that with the normal. But I havent actually implemented a torus model in AVS so I'm not going to pretend to be an authority on it.
Like Jaak says you need to post an updated version of the preset really, that version you posted at the start is just a ring of dots :P
ASD5A
19th April 2005 15:06 UTC
i finally solved the problem.
i have split that superscope into two:
one with z3<0 and one with z3>0;
i added noexecution for performance issues(the if(skip,...);doubles my framerate ;))
here is the correctet version.
thank you all for providing help.
Jaak
19th April 2005 17:09 UTC
nope, it doesn`t fix the problem 100%
torus still occludes itself under certain angles
[edit]
make it resolution independent and bigger... i`d make it myself, but the code you have produced is absolutely ugly, unoptimized and uncommented... not that it means there is something wrong with your coding skill :p
ASD5A
19th April 2005 18:51 UTC
do you mean the torus itself or the resolution of the grid ?
yes it´s not 100% perfect but the rest is only tweaking values, nothing to bother you.