Skip to main content
GameDev.net gamedev.net
🔒 Locked

Raytracing wireframe

Started by Aenimal Nov 29, 2002 at 2:50 PM 12 replies 4.8k views
Original Post
Aenimal
Aenimal
Is there a clever way to raytrace polygons (tris and quads but all should be the same right?)in wireframe? I have tried to clip the middle of the polygons myself but my idea wasn´t distance independent, so when I rerender my scene at a closer distance all lines became thicker. Is there a solution to this or must I implement a standard rastericer?
JuNC
JuNC
I suppose you could determine the intersection of the ray with the triangles plane, then work out the closest distance to each edge of the triangle, then use a threshold (and possibly some distance function to do antialiasing) to determine whether it hits or not. Haven''t seen any actual papers on this but it sounds like it should work.
Aenimal
Aenimal
What you are describing is exactly what I have tried. Say that I have my u,v weights (dunno what you call them) in barycentric coordinates and I clip like u in the range of greater then 0 to 0.001 for example. That might look good from one viewing distance but from another the lines may become thick. What I would like is to raytrace lines that are always one pixel thick. Antialiasing comes automagically from supersampling/jittering etc. later on.
Oh by the way thanks for your answer
JuNC
JuNC
Oh yeah, I see what the problem would be now, it's the same problem as aliasing because of the limited resolution further away from the camera. I don't see why the edges become 'thicker', you would certainly get drop-outs because the rays miss, do you have an image or two you could show us how it looks?

Maybe you could try intersecting the ray with a plane parallel to the screen, then projecting all the triangle edges onto that plane and doing the same process you are doing.


EDIT:
hehe, I just realised what I described above is exactly why lines would become thicker - just the other way around. For some reason I was thinking you meant they'd get thicker as they went away from the camera *doh*

[edited by - JuNC on November 30, 2002 7:23:56 AM]
Aenimal
Aenimal
I think I understand your post (having some language problems here, haven´t had english classes for 7-8 years..). But as you mentioned in your edit this is where my problem originates from. I think Anyway at first I thought that I could scale the delta value from my previous example u > 0 and u < delta acording to distance from viewer. But this seems hard to find such a delta that makes lines have thickness one at all time. Should I give up my evil hacks and start to implement a rastericer instead? But then I won´t get that nice shadowed wireframe that we all crave, right?
JuNC
JuNC
Sorry I think I got a bit fragmented in that post, I edited it about four times before finishing.

The main idea was to project the triangles onto some plane (the screen plane would work) and then perform the ray intersection with that plane only.

Then you would do the edge-distance test to determine whether the ray hits an edge.

This would be done after any gross culling you might do with an octree or whatever.

I'll try and work out the math tommorrow, I'm a little drunk right now

EDIT:
YOU WANT SHADOWS AS WELL???? Just re-read the end of your post. Hmm, that's going to be trickier...

[edited by - JuNC on November 30, 2002 6:12:35 PM]
Aenimal
Aenimal
Ok I think I´ll better make one thing clear. I am not asking how to implement any other stuff than if it´s possible to raytrace polygons in wireframe. Not how to implement any general shadow algos or anything. Just so you don´t missunderstand me
I have made an example image of the problem. here What you are seeing is a "wireframe" cube raytraced at 2 units from eye/camera and one, the right one 5 units away from eye/camera. The methos used in the picture the one I described earlier. Clip the middle of the triangles. The delta in the picture is constant. As I understand that is what you suggest. My problem is now, how do I get a near perfect delta? Or maybe another method perhaps? I think I need to get wasted, maybe then all pieces will fit together
JuNC
JuNC
No, no I didn''t think you needed help with general shadows, it''s just that the method I was suggesting would require projecting every triangle onto every lightsource for every point that could be shadowed.

Yeah, the two methods are similar. Ok the method relies on having a sane viewing plane, fish-eye or other weird shape will be hard.

Now the way I was thinking was to project the triangle onto the screen plane, something like take lines from each vertex to the eye point and find their intersection on the screen plane (or use standard tumble/projection transforms). The problem is then purely 2D and the delta is taken care of in the projection.

Hmm, finding the point in world space for lighting is a bit trickier but it can be done.

Now shadowing can be done in a similar way (with point lights at least), just pick a plane orthogonal to the shadow ray and project the edges onto that plane instead.

However, whether this is actually worth doing is another question. A scanline renderer would probably be quicker.

Aenimal
Aenimal
Yup you are right. I am gonna combine my scanline renderer with my raytracer and implement shadowmaps instead. Thanks for the discussion
JuNC
JuNC
Cool, post some screenies when you''re done, I''d like to see how it looks
Evangelion
Evangelion
Why are you ray tracing a wireframe model? The whole point of raycasting is to do HSR, lighting, ect. None of which are done on Wireframes.

BTW -> if you mean to draw only the polygons that would be visible if the mesh were not wireframe, you could cheat a little and make the inside of the triangle transparent.
TerranFury
TerranFury
Methinks this is a lot simpler than you realize. Rather then coloring the triangle just with a distance-from-edge threshhold, do it based on the distance-from-edge-times-distance-from-camera. That''ll make lines farther away larger in world space, and the same size in camera space. (I think.)
Aenimal
Aenimal
JuNC - if ever get finished I´ll do that

Evangelion - Why? Because I thought it could be nice to have that option in my raytracer The idea was if I could find some way to raytrace the lines then I would have shadows "for free" from my already implemented routines..
"if you mean to draw only the polygons that would be visible if the mesh were not wireframe" isn´t this what a raytracer normaly render?
" you could cheat a little and make the inside of the triangle transparent" that´s what we have been talking about here, right?

TerranFury - Thats the same idea I posted. The problem is how to find constants that make the lines one pixel wide at all distances. Anyway as I said earlier I have ditch that idea and I am doing scanline rendering instead.
Aenimal
Aenimal
I am an ignorant fool :D
Sorry Evangelion if my last post sounded harsh, I was in a funny mood when a answered.
And TerranFury, I had decided even before I finished your post that you were talking about the same method as I purposed. But when I took the train home today I thought it over. Did some simple tests when I came home. Looked rather nice Some artifacts left but they might disappear with some tweaking. Thanks.
Here´s a screenie of the same "scene" as before.
picture

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.