PDA

View Full Version : fast shadows on smooth terrain



nguyenc
05-23-2013, 12:28 AM
i have tryed a fast shadow on smooth terrain program in freebasic that works with transparent objects like trees too, and also opengl1.x and above.
heres how it works :
i take a glortho view of the scene from the direction of the light, centered on x,y,z player perso position
glMatrixMode GL_PROJECTION
glLoadIdentity
Var k=900
do2=45 'angle of light
ksin=k*Sin(do2*degtorad):kcos=k*Cos(do2*degtorad)
glortho(-k,k,-ksin,ksin,10,100000)
glmatrixmode gl_modelview
Var dbx=bmpx
glviewport(0,0,dbx,dbx)
tshadow=1
glLoadIdentity ()
If kcos<0 Then glrotatef(180,0,0,1)
glulookat(x,y-kcos*10,z+ksin*10, x,y,z, 0,0,1)
glcolor3f(1,1,1)
...here drawterrain with texture offset & zheight=z(player perso)
glcolor3f(0,0.3,0)
...here draw persos,trees, with zheight=z(player perso)
glReadPixels(0,0, dbx,dbx, GL_rgba, GL_UNSIGNED_BYTE, bmpbits) 'store view to bmpimage buffer
glbindtexture(gl_texture_2d,grasstexture) ' grasstexture=texture used to draw near terrain
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_linear)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_linear)'nomipmap (faster)
glTexSubImage2D(GL_TEXTURE_2D, 0, 0,0,bmpx,bmpy, GL_rgba, GL_UNSIGNED_BYTE, bmpbits)
' store bmpimage buffer in terrain texture

'then i draw normal scene
glMatrixMode GL_PROJECTION
glLoadIdentity
' anglevue xmax/ymax mxmin,mxmax
gluPerspective 48, xmax/ymax, 3.3, 100000
glmatrixmode gl_modelview
glviewport(0,0,xmax,ymax)
glcolor3f(1,1,1)
tshadow=0
... here draw normal scene with terrain texture,persos,trees, near terrain texture=texture with shadows

works with smooth terrain

you can find an example with source on freebasic forum

http://1.bp.blogspot.com/-sI4iv6vzJmY/UY4v4vXHA5I/AAAAAAAAAsg/8cMWvVDsBVg/s1600/perso3D_chung9.jpg

Nowhere-01
05-23-2013, 12:58 AM
it's not a question, stop spamming your site.

nguyenc
05-25-2013, 02:23 AM
enhanced shadows speed :
glreadpixels + gltexsubimage2d replaced by glcopytexsubimage2D

glcopyTexSubImage2D(GL_TEXTURE_2D, 0, 0,0, 0,0,bmpx,bmpy) (direct copy from frame buffer to texture)

thokra
05-25-2013, 03:36 AM
Dude, nobody cares. O_o

This is a forum for asking questions and discussing topics related to OpenGL directly, not some algorithm that just happens to be implemented using OpenGL that seems to work fine. If you have a specific problem with your algorithm that's cool. Otherwise, please put your ideas somewhere else, a blog, your own website and so forth...

BTW, algorithms implemented using hardcore, immediate-mode legacy GL aren't particularly sexy in 2013 ...

Alfonse Reinheart
05-25-2013, 06:05 AM
enhanced shadows speed :
glreadpixels + gltexsubimage2d replaced by glcopytexsubimage2D

glcopyTexSubImage2D(GL_TEXTURE_2D, 0, 0,0, 0,0,bmpx,bmpy) (direct copy from frame buffer to texture)

You know what would "enhance" your "shadows speed" more? Rendering directly to the texture (http://www.opengl.org/wiki/Framebuffer_Object).

This is 2013; if you're using glCopyTexSubImage for almost any reason, you're doing it wrong.

Nowhere-01
05-25-2013, 06:18 AM
well, his application shows 8 FPS in that scene. even on a crappiest laptop with the scene like that, it should be a 3-digit number. i would like to see real source code just for the sake of entertainment. i'm not sure if glCopyTexSubImage can cause such performance solely, unless you're trying to do it on purpose.