Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: fast shadows on smooth terrain

  1. #1
    Junior Member Newbie
    Join Date
    May 2013
    Posts
    9

    fast shadows on smooth terrain

    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

    Last edited by nguyenc; 05-23-2013 at 05:31 AM.

  2. #2
    Member Regular Contributor Nowhere-01's Avatar
    Join Date
    Feb 2011
    Location
    Novosibirsk
    Posts
    251
    it's not a question, stop spamming your site.

  3. #3
    Junior Member Newbie
    Join Date
    May 2013
    Posts
    9
    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)

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,129
    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 ...

  5. #5
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    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.

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

  6. #6
    Member Regular Contributor Nowhere-01's Avatar
    Join Date
    Feb 2011
    Location
    Novosibirsk
    Posts
    251
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •