My VirtualGL lib again - showcase&cry for help
Blitz3D Forums/Blitz3D Programming/My VirtualGL lib again - showcase&cry for help
| ||
hi! as you see in the pic below, the textures are drawn linear, and not perspectively correct. i read in a forum thread about how it works. the link ain't working no more. anyway, i just dont get it! how is it working? ![]() download: http://stuff.dev-ch.de/index.php?article=stuff_virtualgl please help me where you can :)thanks for the help in the other threads, too!! bye |
| ||
That model is where you're problem lies. The organization of polies defining the bonnet and windscreen are particularly horrid. Re-model it using some nice symetrical quads, along the lines of the pic below (doesn't necessarily have to be this hi-poly), and it should texture fine. ![]() |
| ||
i think you didnt understand my problem. when you use this many polys, it will be drawn all right, but with low poly models, the whole render looks bad. what i want to do is bring some perspective in it like that: example: ![]() ![]() |
| ||
Assuming I'm understanding you correctly, that can't be done. It may be possible to do that type of thing with shaders (I don't know about such things), but with simple UV mapping? No. |
| ||
What you have to do is compute u/z and v/z (call these s and t) at the corners and interpolate those instead of u and v. Also interpolate 1/z (call that w) instead of z. Then, at each pixel you need to get z, and this is where the divide comes in. At each pixel z = 1/w u = s*z v = t*z If you're doing this in fixed point, be very, very careful about number precision and ranges. 1/z is difficult to compute in fixed point as well as having a good range and precision. Jim Bibo ergo sum from here: http://p205.ezboard.com/very-fast-3d-duel-screen-demo/fyabasicprogrammingfrm25.showMessage?topicID=23.topic ^^ that guy explained it, but i didnt manage to implement it. also here are some examples: http://p205.ezboard.com/BlitzBasic/fyabasicprogrammingfrm22 http://p205.ezboard.com/3D-Engine-Source/fyabasicprogrammingfrm22.showMessage?topicID=167.topic (i didn't manage to learn from them) i sound like a noob right now, but believe me, it is harder than you think. also i dont want to copy&paste the whole source code. |
| ||
This might help you, it also has some code examples and optimisations. http://www.gamedev.net/reference/articles/article331.asp and here http://www.lysator.liu.se/~mikaelk/doc/perspectivetexture/ |
| ||
I had a very quick look. Your uv's are loaded as float but passed to ( and referenced ) in alot of functions as integers. Not sure if that's intentional or how much of a difference that this'll make but worth considering. Stevie |
| ||
i pass it further as integer using <SHL 16> this is all right this way. thanks for that references, i will take a look at it. i hope i get it working, but i expect, that it wont. i'll come back if it doesnt work in a while bye:) |
| ||
ok, i read and tried both. no success yet. is here anybody, who could help me this far, that it works? - i mean, wheter, anybody could implement that piece of code into my program. ps: dont take this the wrong way: i'm not bagging for source code!!! i'm just asking for advice:) |
| ||
well, it's really imprtant for me, that the perspective correction works. is here anybody who can help me this far that it actually works? :(![]() ![]() |
| ||
Try this code which I believe was originally by Sswift which I put a wrapper on. My understanding (though I could be wrong) is that it removes shared vertices and gives each surface it's own. |
| ||
this does not solve my problem. i think the two pics with the "==>" between them are showing the exact problem. |
| ||
You are coding this in Blitz3D, right (this is a B3D forum afterall)? So, I don't understand how you expect to get such low-level control over texturing. |
| ||
dont know what you mean... http://p205.ezboard.com/fyabasicprogrammingfrm22.showMessage?topicID=164.topic this link shows perspective corrected texture mapping. but i didt get it. how does it work? i still dont understand :( am i too stupid? |
| ||
Oh, this is for a software renderer? I see. |
| ||
yes. as you see in the link i posted above, it certainly is possible. but i still didnt get it :( |
| ||
i would really appreciate it if someone would help me. remember that i've done a lot for this community and not only for this) |
| ||
ok. i found help in an other forum. thank you guys anyway.![]() |
| ||
hi all, i have changed the your function renderline. [code] Function vgliFillTriLine(p1x, p1d, p1u, p1v, p2x, p2d, p2u, p2v, y) If p1x > p2x Then tx = p1x : td = p1d : tu = p1u : tv = p1v p1x = p2x : p1d = p2d : p1u = p2u : p1v = p2v p2x = tx : p2d = td : p2u = tu : p2v = tv EndIf p1x = p1x+vglViewportX p2x = p2x+vglViewportX Local dif= (p2x - p1x) Local fact=0 If p1x <vglViewportX Then fact= -p1x p1x = vglViewportX EndIf If p1x => p2x Then Return Local id = (p2d - p1d) / dif Local iu = (p2u - p1u) / dif Local iv = (p2v - p1v) / dif Local tw = (vglTex\w Shl vglShlUV)-1 Local th = (vglTex\h Shl vglShlUV)-1 Local d = p1d + (fact*id) Local u = ((p1u + vglShlUV2) Mod tw) + (fact*iu) Local v = ((p1v + vglShlUV2) Mod th) + (fact*iv) tex.vglTexture = vglTex If p2x >(vglViewportX+vglViewportW) Then p2x = (vglViewportX+vglViewportW ) y2 = y + vglViewportY Local texw = tex\h ;texture 512 = shl 9 For x = p1x To p2x ;===> If u > tw Then u = 0 If v > th Then v = 0 If u < 0 Then u = tw If v < 0 Then v = th ;===> If d < vglBuffer(x, y) Then vglBuffer(x, y) = d ; WritePixelFast x, y2 , tex\texel[((v Shr vglShlUV) * shl 9 ) + (u Shr vglShlUV)] WritePixelFast x, y2 , tex\texel[((v Shr vglShlUV) * texw ) + (u Shr vglShlUV)] EndIf d = d + id u = u + iu v = v + iv Next End Function /[code] |
| ||
thank you for these tips. some of them made me think. also i couldnt take it this way because i changed a lot since the last version published here. but i will take a very sharp look at these here is the new version http://stuff.dev-ch.de/index.php?article=stuff_virtualgl (now supporting a z-buffer instead of a w-buffer) btw: ![]() |
| ||
Software renderers rule. I love this! |