06/12/95 nts_pers.txt ver 0.1 alpha :) fast perspective-texturemapping ------------------------------- Everything you read in this text is based on my own experience. So, it might not even be perspective texturemapping... but it sure looks A LOT like it .... If anyone knows this allready exists let me know it please... BTW : This is a text to _optimize_ realtime perpective texture mapping I know the text is poorly written, but hey, it should work... The inner loop needs 4 ADDs to calc x and y pos in pic (in opposition to the 2 DIVs and 3 ADDs ? normally used) PS : you might even call it _Natas mapping_ 8-) Enjoy... -> Natas --------------------------------- Thx 2 the followin people : Nostromo : for the enthousiasm in codin... Infernus : for .... (you know) Tempest : the same... N0rdie : for spurring me 2 follow the lessons ;) Zephyr : for the utils for Unix & Irc :) Turbo & Mig : for the booze... (harhar) Everyone on IRC, especially Valhalla : sharing ideas about this stuff... Sdw : showin interest, and motivating me 2 release this ;) some names...everyone i can remember right now ... antibyte,distance,flynn,gongo,sleeping dog,ZEPHYR,N0RDiE, thefear,ALL DUDES FROM NL,bitbyter,zed,zhivago,therew,Davenger, beam,trug,wiz_nfo,Random,... if you are not here, than i probably couldn't remember yar name ): contact me... i'll fix it... ---------------------------------------------- conventions: (sx,sy) : screenpos (x1,y1,z1) : point 1 (x2,y2,z2) : point 2 When you know x, y and z you normally do the following calculations : sx = x / z to get 2d coordinates. sy = y / z so, 3d texture mapping would normally be (with only linear functions, and without any rotation or scaling...) : x = sx * z y = sy * z This works, but is way to slow i think, so maybe THIS IS FASTER.... Let's take a var t, screenpos on the screen (sx) then we could represent current x,y and z as functions in order to F(t): x = a * t + b (a = (x2-x1), b = x1 ) y = c * t + d (c = (y2-y1), d = y1 ) z = e * t + f (e = (z2-z1), f = z1 ) Now, let's fill in x and z into the formula x=sx*z x = (a*t + b) * (e*t + f) <=> x = a*e*t^2 + (af+be)*t + bf Now we could simplificate this using ADDs & derived functions: -> for function (af+be)*t : F (t) = (af+be)*t F'(t) = (af+be) So, each time, we simply add (af+be) to f(t) example : x = = 0(af+be) x = 0 + (af+be) = 1(af+be) x = (af+be) + (af+be) = 2(af+be) x = 2(af+be) + (af+be) = 3(af+be) ... So, the implementation is +------------------------------+ | x = 0 | | for t=1 to length do begin | | dostuff | | x = x + (af+be) | | end; | +------------------------------+ -> Function (a*e*t^2) is harder... here we need 2 derives F (t) = a*e*t^2 F' (t) = 2*a*e*t F''(t) = 2*a*e So here, you need to do the following : x = = 0 q = = 1*a*e x = 0 + 1*a*e = 1*a*e q = 1*a*e + 2*a*e = 3*a*e x = 1*a*e + 3*a*e = 4*a*e q = 3*a*e + 2*a*e = 5*a*e x = 4*a*e + 5*a*e = 9*a*e q = 5*a*e + 2*a*e = 7*a*e .... So, the implementation is +------------------------------+ | x = 0 | | q = 1*a*e | | for t=1 to length do begin | | dostuff | | x = x + q | | q = q + 2*a*e | | end; | +------------------------------+ -> total implementation of the function will be (for x and y) +------------------------------+ | x = bf | | y = df | | q = a*e | | r = c*e | | for t=1 to length do begin | | dostuff | | x=x+q+(af+be) | | y=y+r+(cf+de) | | q=q+2*a*e | | r=r+2*c*e | | end; | +------------------------------+ -> btw : normally it should be: x=x+q+(af+be) y=y+r+(cf+de) so if you simply add (af+be) and (cf+de) once to q & r, they won't be needed anymore +------------------------------+ | x = bf | | y = df | | q = a*e + (af+be) | | r = c*e + (cf+de) | | for t=1 to length do begin | | dostuff | | x=x+q | | y=y+r | | q=q+2*a*e | | r=r+2*c*e | | end; | +------------------------------+ So, this should be MUCH ? faster... Now for the rotation... figure it out yourselves... it's not really difficult... =) You can make use -again- of the derived functions... I don't even need additional calculations / pixel in my routine. ( If you know how to do rotozoom, you know how to do this !!!! ) I hope you can do something with this... I guess there are still some errs in this txt, but hey, it's a start !!! RIGHT NOW YOU SHOULD BE ABLE TO DO A PERSPMAP OF YOUR SCREEN... TRY TO CONVERT IT INTO A POLY ROUTINE !!! +-----------------------------------------------------------------+ | NOTE : i've allready worked a perspline routine out in 3D... | | (only theory, though....): | | | | Params : screen(x1,x2,y),pic(x1,x2,y1,y2),3D(z1,z2) | | | | important: only mathematical instr, no fixedpoint imple- | | mentation, stosb, moves,loop cnts,... included | | | | Precalc/line : 2 DIV,8 MUL,5 SUB,2 SAL | | Instr/pixel : 4 ADDS | | | | Scanconvert not included...i'll use the same stuff for it...| +-----------------------------------------------------------------+ | You could accept this overview as a hint... | | Really easy from here on ;) | | (if u know some mathematics) | +-----------------------------------------------------------------+ ! IF u use this in any of your stuff, i'd like some greets... ! I guess it's a small effort for the research i did on it... Companies... contact me first please ! Greetings, Tom Janssens, a.k.a. Natas from Digital Labs - Cathedral -------------------------------------------------------------------------- for comments, questions (a lot i guess),money donations :),... Address : Tom Janssens Gentsesteenweg 202 9620 ZOTTEGEM BELGIUM tel: +32-(0)9/360.17.40 if u have any luck, u can find me on IRC, channel #coders, nick should be "_Natas_" -------------------------------------------------------------------------- Remember : Only !LAME! people rip without giving credz !!! Blah... Netsplit detected .... :))