PDA

View Full Version : how to control rendering contrast



Eggman
16-01-2010, 03:53
Hi,

I have set my mind on making a small movie sequence using thinbasic (based on the earth & moon sample program), but in my lack of experience in the modern programming world I run into some problems concerning rendering images to my liking

I want to have bigger contrast in the rendering. so far I have not been able to find a way to have textured objects being dark where there is no lights. So if you look at the sun from behind the earth, the night part of the earth is still pretty light.

Perhaps this could be solved by turning the light of the sun off and make it somehow selfilluminating and pointing spots from the sun towards all the other objects, or by changing the mapping behaviour somehow, or by increasing contrast in the rendering. Only the first solution I have an idea how this may be done, but this also seems a bit of an extreme measure. Since I would also like to change the color spectrum fooling around with contrast / color bias would seem the best option to me, but I haven't got the slightest idea how this could be done. (not entirely true, I have a bit of an idea that this may have to do with the TBGL_setlightparameter command, but so far that didn't make the nightside of the earth dark and also didn't help to make eerything more grey-ish

Can anybody give me some idea how to deal with this?

Thanks,

David

kryton9
16-01-2010, 09:08
Petr can get back to you on this. But I am sure it will be something doing post processing, like motion blur and bloom. I am sure you could just as easily lay a color gradient in there also. http://psch.thinbasic.com/articles.html

That link should give you a good start till Petr replies back.

Petr Schreiber
16-01-2010, 11:29
Hi Eggman,

and welcome to the forums!

You were on the right track - it is necessary to modify light properties.
The property to modify the color on the unlit side of objects is called "ambient".

Way #1
To get more extreme contrast, you can set the ambient color to negative values:


TBGL_SetLightParameter %GL_LIGHT0, %TBGL_LIGHT_AMBIENT, -0.5, -0.5, -0.5, 1

The fact 0,0,0 does not result in dark side of the Moon is that OpenGL defaults the materials slightly oddly.

Way #2 - the more correct one
But don't worry, TBGL has easy solution, more elegant than negative colors.
The light interaction model is in fact defined by material and light.

In latest betaversion of thinBASIC (which I recommend to download (http://community.thinbasic.com/index.php?topic=2899.0)), you can define materials too.

With it, it is only necessary to specify the ambient light to black:

TBGL_SetLightParameter %GL_LIGHT0, %TBGL_LIGHT_AMBIENT, 0, 0, 0, 1

Define material with black ambient component:


Dim mDark As Long = TBGL_NewMaterial
TBGL_SetMaterialAmbient(mDark, 0, 0, 0)


And then render the planet with this material enabled:


TBGL_PushMaterial(mDark)
' -- Render planet here

' -- Render cloud layer here
TBGL_PopMaterial


You will see the unlit parts will be completely black as on the attached image.

Let me know if this is what you want.

Then there is also way to draw full screen semi-transparent rectangle over whole scene to do some color toning.
This is base for the post processing Kent was talking about, but I think it is not necessary here. Properly setup materials and light should do the job.


Petr

P.S. One little hint - if you are into animation, I recommend you to rebuild the example using tbgl scene-entity system. I use it to work on animations myself, and the work with objects is much easier then.
Each object has "name" by which you reference it, you can push/rotate/scale it very easily. If you are interested, I can show you how.

Also - if you want the spheres more round, use:

tbgl_SetPrimitiveQuality 50
... or even higher than 50 for super smooth look.

Michael Hartlef
16-01-2010, 12:00
Hi eggman and welcome to the forum.

Well, I created an example with lights but I didn't thought about the material solution. I will attach the code anyway so maybe someone has a use for it.




'=============================================================================
'= TBGL Sample Script =
'= Light Demo using the entity system =
'= =
'= Michael Hartlef, 2010 =
'=============================================================================

'-- Load the TBGL module
Uses "TBGL"

Dim hWnd As Dword
dim FrameRate as double
dim Sheeps as long

'-- Create a TBGL window and show it
hWnd = TBGL_CreateWindowEx("Light demo - press ESC to quit", 800, 600, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX )
TBGL_ShowWindow

'-- define the ID's for all the entities and other objects
Begin Const
%myScene = 1 'The entity object ID's have to be a positive number
%ent_Camera = 2
%ent_Sphere
%ent_Sphere2
%ent_Sphere3
%ent_light
End Const

'-- Now create a world that contains all the entities
TBGL_SceneCreate(%myScene)


'-- Next create a camera to view the scene
TBGL_EntityCreateCamera( %myScene, %ent_Camera)
TBGL_EntitySetPos ( %myScene, %ent_Camera, 0.0, 7, 20.0 )

'-- Create two spheres so we have something to look at
TBGL_EntityCreateSphere( %myScene, %ent_Sphere ,0 ,1 , 0, 255,0,0 )
'TBGL_EntityCreateBox( %myScene, %ent_Sphere ,0 ,1 ,1,1, 0, 255,0,0 )
TBGL_EntitySetPos( %myScene, %ent_Sphere, -3, 0, 0 )
TBGL_EntityCreateSphere( %myScene, %ent_Sphere2 ,0 ,1 , 0, 0,255,0 )

'-- Let the camera look at sphere no.2
TBGL_EntitySetTarget( %myScene, %ent_Camera, %ent_Sphere2 )

'-- Now create a light, position it and let it look at sphere no.1
TBGL_EntityCreateLight( %myScene, %ent_light , 0 , %TBGL_LIGHTTYPE_SPOT )
TBGL_EntityCreateSphere( %myScene, %ent_Sphere3, %ent_Light,0.2)
TBGL_EntitySetBorderFade( %myScene, %ent_light, 25 )
TBGL_EntitySetPos( %myScene, %ent_light, 7, 5, 0 )


'---Resets key status before checking
TBGL_ResetKeyState()

'---Main script loop
WHILE TBGL_IsWindow(hWnd)

'---Script will run on different PCs so we must assure
'---constant speed of movement by scaling movements relative to frame rate
FrameRate = TBGL_getFrameRate

'Turn the light towards sphere no.1
TBGL_EntitySetTarget( %myScene, %ent_light, %ent_Sphere )

'-- Clear the frame
TBGL_ClearFrame

tbgl_SceneRender(%myScene)

TBGL_DrawFrame ' Swaps the buffers - displays rendered image

If TBGL_GetWindowKeyState( hWnd, %VK_UP) Then TBGL_EntityPush(%myScene, %ent_Sphere, 0, 0, -4/FrameRate)
If TBGL_GetWindowKeyState( hWnd, %VK_DOWN) Then TBGL_EntityPush(%myScene, %ent_Sphere, 0, 0, 4/FrameRate)

If TBGL_GetWindowKeyState( hWnd, %VK_PGUP) Then TBGL_EntityPush(%myScene, %ent_Sphere, 0, 4/FrameRate, 0 )
If TBGL_GetWindowKeyState( hWnd, %VK_PGDN) Then TBGL_EntityPush(%myScene, %ent_Sphere, 0, -4/FrameRate, 0 )

If TBGL_GetWindowKeyState( hWnd, %VK_LEFT) Then TBGL_EntityPush(%myScene, %ent_Sphere,-4/FrameRate, 0, 0)
If TBGL_GetWindowKeyState( hWnd, %VK_RIGHT) Then TBGL_EntityPush(%myScene, %ent_Sphere, 4/FrameRate, 0, 0)

'If TBGL_GetWindowKeyState( hWnd, %VK_R) Then TBGL_EntityTurn(%myScene, %ent_Sphere, -50/FrameRate, 0, 0)

If TBGL_GetWindowKeyState( hWnd, %VK_ESCAPE) Then Exit While


WEND

'---Closes OpenGL window
TBGL_DestroyWindow

Petr Schreiber
16-01-2010, 13:16
Thanks Mike,

I think your example is perfect introduction to entity system!

Eggman, after deep study of Mike's example and understanding the principles, you might try to look at this enhanced version of the script.

Planets are already floating in space, and it is possible to watch spotlight direction.
My example shows definition of custom entity object - in this case planet.


Petr

Michael Hartlef
16-01-2010, 14:25
Awesome sample Petr. Like always! :eusaclap:

Eggman
17-01-2010, 04:24
Hi guys,

It's amazing how fast you have responded and many thanks for these and your programming examples. I haven't gotten to study them well yet, let alone implement them, but they look very promising. The negative ambient light is indeed a bit strange (although also pretty interesting that it can be negative!) but I think I'll go for the download of the new version of thinbasic and setup material properties.

I like the rendered images very much! I did find out about primitivequality myself :) Think I will do color toning partly by lighting, but am concerning to combine it (or maybe even do it fully) with blurring.

I'll let you know how I get on. Thanks again (and you'll probably will see much more questions from me in future ;) ) Now I gotta get back to bed again!

kryton9
17-01-2010, 09:49
Nice examples Mike and Petr. It will be a good basis for me to relearn all I forgot in thinBasic.