|
thinBASIC TBGL Website
by Petr Schreiber |
|||||
| Home | Tutorials | Articles | Tools | Links | About |
As you probably noticed, remake of old good Tomb Raider game was released in June 2007.
If you played both games or at least the demos, you can see there is lot of extra eye candy in new version of the game. Do you want your scripts to look cutting edge too? Sure!
Now please let me go through some nice techniques presented in TRA and explain how to achieve it in TBGL.
Keep in mind I have no sources of the game, so my implementation will vary from the original ( not speaking of Tomb Raider is running DirectX 9 and we will use TBGL based on ancient version of OpenGL :) )
Things to focus to
Regarding graphic techniques, I chose quite sundry ones.
First I will show you the most evident and visually stunning effect - the glow. Then I will guess how developers implemented wild water near waterfall and finally I will present really basic stuff used to mark enemies.
For your comfort I will explain all stuff on scenes from TRA demoversion, which you can get for free anywhere on the net. This way you can compare results we achieved using TBGL and original.
When you will go through the text you should get the idea, and at the end you can download sources demonstrating each technique.
Part One: The mighty glow
As I said, this effect is the nicest thing you will notice immediately. In TR it is used in cutscenes and when Lara swims under water surface or is nearby some bright light source.
This technique somehow makes image look softer, bit blury and really hi-tech :).
If you don't get the idea from my confusing explanation, please click on the screenshot placed somewhere nearby.
' -- Prepare post process texture buffer
WHILE TBGL_ISWINDOW( hWnd )
' * First pass *
TBGL_CLEARFRAME
' -- Setup scene for render to texture
' -- Draw it
' -- Pass to texture
' * Second pass *
TBGL_CLEARFRAME
' -- Setup scene normally
' -- Draw it
' -- Draw post process layer
TBGL_DRAWFRAME
' -- Here some code to exit loop :)
WEND
SUB PostProcess_Init( textureSlot AS LONG, textureSize AS LONG)
GLOBAL PostProcess_TextureID AS LONG = textureSlot
GLOBAL PostProcess_TextureSIZE AS LONG = textureSize
TBGL_USETEXTURING %TRUE
TBGL_BINDTEXTURE PostProcess_TextureID
DIM TexStr AS STRING = REPEAT$( textureSize * textureSize * 3, $SPC )
TBGL_MAKETEXTURE (TexStr, %TBGL_DATA_RGB, _
textureSize, textureSize, textureSlot, _
%TBGL_TEX_LINEAR )
END SUB
SUB PostProcess_PrepareViewPort()
TBGL_VIEWPORT(0, 0, _
PostProcess_TextureSIZE, PostProcess_TextureSIZE, _
%TBGL_PARAM_PIXELS)
END SUB
SUB PostProcess_GetTexture()
TBGL_RENDERTOTEXTURE(PostProcess_TextureID, 0, 0, _
PostProcess_TextureSIZE , PostProcess_TextureSIZE)
END SUB
SUB PostProcess_Render_glow( glowOffset AS LONG, nPass AS LONG, _
toneR AS BYTE, toneG AS BYTE, toneB AS BYTE)
LOCAL i AS LONG
LOCAL cx, cy AS LONG
LOCAL fxStep AS SINGLE = 360/nPass
LOCAL angle, xShift, yShift AS SINGLE
TBGL_GETWINDOWCLIENT hWnd, cx, cy
TBGL_RENDERMATRIX2D
TBGL_BINDTEXTURE PostProcess_TextureID
TBGL_USELIGHTING %FALSE
TBGL_USEBLEND %TRUE
TBGL_USEDEPTHMASK %FALSE
TBGL_COLOR toneR,toneG,toneB
FOR i = 1 TO 360 STEP fxStep
angle = i * 0.0174532925199433
xShift = SIN(angle)*glowOffset
yShift = COS(angle)*glowOffset
TBGL_BEGINPOLY %GL_QUADS
TBGL_TEXCOORD2D 0,0 : TBGL_VERTEX xShift , yShift
TBGL_TEXCOORD2D 0,1 : TBGL_VERTEX xShift , cy+yShift
TBGL_TEXCOORD2D 1,1 : TBGL_VERTEX cx+xShift, cy+yShift
TBGL_TEXCOORD2D 1,0 : TBGL_VERTEX cx+xShift , yShift
TBGL_ENDPOLY
NEXT
TBGL_COLORALPHA 32,32,32,64
TBGL_USEBLEND %FALSE
TBGL_USEDEPTHMASK %TRUE
TBGL_USELIGHTING %TRUE
END SUB
SUB AnimateWater( Model AS LONG, Speed AS SINGLE )
LOCAL Vertices AS LONG = TBGL_M15GETMODELVERTEXCOUNT( model )
LOCAL i AS LONG
LOCAL u,v AS NUMBER
' -- Just adding number to one coordinate
FOR i = 1 TO Vertices
v = TBGL_M15GETVERTEXTEXY( model, i)
v += Speed / FrameRate
TBGL_M15SETVERTEXTEXY( model, i, v)
NEXT
END SUB
' ...
TBGL_RENDERMATRIX3D
' -- Render scene
' ...
' -- Only if something is selected ...
IF ObjectMarked THEN
' -- Here we check if object is not blocked by other
' -- as reference point is inside Object ( never visible )
' -- we must move out of the radius
IF TBGL_ISPOINTVISIBLE (myObject(ObjectMarked).x, _
myObject(ObjectMarked).y, _
myObject(ObjectMarked).z+1.1) THEN
TBGL_COLOR 255, 0, 0
' -- Unproject the 3D position to 2D is easy
TBGL_POS3DTOPOS2D myObject(ObjectMarked).x, _
myObject(ObjectMarked).y, _
myObject(ObjectMarked).z, pixelX, pixelY
' -- We will render as in 2D ( pixels )
TBGL_RENDERMATRIX2D
' -- No depth to avoid "Z-fight"
TBGL_USEDEPTHMASK %FALSE
' -- No light for the red arrows
TBGL_USELIGHTING %FALSE
' -- This draws 3 triangles - our basic marker
TBGL_PUSHMATRIX
TBGL_TRANSLATE pixelX, pixelY,0
' -- Draw billboard/ geometry here ... using pixels as units
TBGL_ROTATE GETTICKCOUNT/10,0,0,1
FOR i = 1 TO 3
TBGL_ROTATE 120,0,0,1
TBGL_BEGINPOLY %GL_TRIANGLES
TBGL_VERTEX -40,10
TBGL_VERTEX -20,0
TBGL_VERTEX -40,-10
TBGL_ENDPOLY
NEXT
TBGL_POPMATRIX
' -- Back the states we put
TBGL_USEDEPTHMASK %TRUE
TBGL_USELIGHTING %TRUE
END IF
END IF
' ...| © Petr Schreiber 2012 |