Results 1 to 8 of 8

Thread: how to control rendering contrast

  1. #1

    how to control rendering contrast

    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

  2. #2
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: how to control rendering contrast

    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.
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  3. #3
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,129
    Rep Power
    732

    Re: how to control rendering contrast

    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:
    [code=thinbasic]
    TBGL_SetLightParameter %GL_LIGHT0, %TBGL_LIGHT_AMBIENT, -0.5, -0.5, -0.5, 1
    [/code]
    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), you can define materials too.

    With it, it is only necessary to specify the ambient light to black:
    [code=thinbasic]TBGL_SetLightParameter %GL_LIGHT0, %TBGL_LIGHT_AMBIENT, 0, 0, 0, 1 [/code]

    Define material with black ambient component:
    [code=thinbasic]
    Dim mDark As Long = TBGL_NewMaterial
    TBGL_SetMaterialAmbient(mDark, 0, 0, 0)
    [/code]

    And then render the planet with this material enabled:
    [code=thinbasic]
    TBGL_PushMaterial(mDark)
    ' -- Render planet here

    ' -- Render cloud layer here
    TBGL_PopMaterial
    [/code]

    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:
    [code=thinBasic]tbgl_SetPrimitiveQuality 50[/code]
    ... or even higher than 50 for super smooth look.
    Attached Images Attached Images
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  4. #4

    Re: how to control rendering contrast

    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.

    [code=thinbasic]

    '=============================================================================
    '= 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



    [/code]
    Attached Files Attached Files

  5. #5
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,129
    Rep Power
    732

    Re: how to control rendering contrast

    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
    Attached Images Attached Images
    Attached Files Attached Files
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  6. #6

    Re: how to control rendering contrast

    Awesome sample Petr. Like always!

  7. #7

    Re: how to control rendering contrast

    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!

  8. #8
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    67
    Posts
    3,869
    Rep Power
    404

    Re: how to control rendering contrast

    Nice examples Mike and Petr. It will be a good basis for me to relearn all I forgot in thinBasic.
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

Similar Threads

  1. contrast (color) illusion
    By Lionheart008 in forum UI (User Interface)
    Replies: 13
    Last Post: 29-06-2010, 14:06

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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