Results 1 to 9 of 9

Thread: Basic example on passing value from ThinBASIC to shader

  1. #1
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    6,795
    Blog Entries
    3
    Rep Power
    693

    Basic example on passing value from ThinBASIC to shader

    GLSL shaders are indeed very useful tool for creating unusual graphic output.
    Sometimes you need to change shader behavior after compilation dynamically.
    There is interesting mechanism, which allows change shader variable values according to your ThinBASIC variables.

    The magic OpenGL commands to achieve this are two:
    glGetUniformLocationARB - to retrieve "pointer" to shader variable
    glUniform1fARB - to change variable located at "pointer" to other floating point value

    The attached script demonstrates this technique in the easiest way. Just use slider to modify the variable value and watch the impact on shader in realtime.

    Note: As this script demonstrates advanced technique, your card must be GLSL compatible. That means ideally support for OpenGL 2.0 or OpenGL 1.5 with extensions. Tested on GeForce 9500GT.
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	TBGL_ThinBASICVariableAndShaderBinding.png 
Views:	161 
Size:	12.6 KB 
ID:	6096  
    Attached Files Attached Files
    Last edited by Petr Schreiber; 19-05-2013 at 15:30.
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 7 64bit - Intel Core 2 Duo T6600 @ 2.2GHz - 4 GB RAM - NVIDIA GeForce G210M 512MB
    Windows 8 64bit - Intel Core i5-3350P @ 3.1GHz - 8 GB RAM - NVIDIA GeForce GT640 3GB

  2. #2
    thinBasic MVPs Michael Hartlef's Avatar
    Join Date
    Sep 2006
    Location
    Leverkusen, Germany
    Age
    51
    Posts
    3,278
    Blog Entries
    2
    Rep Power
    339

    Re: Basic example on passing value from ThinBASIC to shader

    Looks nice!
    Running Windows 7 Home, 64 bit, 8 GB ram, Athlon II X2 255, ATI Radeon HD 4200.

  3. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    50
    Posts
    8,184
    Blog Entries
    2
    Rep Power
    10

    Re: Basic example on passing value from ThinBASIC to shader

    Smart, elegant, flicker free, fast, interpreted and ... just 200 lines of code.

    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

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

    Re: Basic example on passing value from ThinBASIC to shader

    Petr, when do you find the time? I know how busy you are and yet you throw us surprises often. I guess just like Eros and Mike you guys find a way!
    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

  5. #5
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    6,795
    Blog Entries
    3
    Rep Power
    693

    Re: Basic example on passing value from ThinBASIC to shader

    Hi Kent,

    nice to see you here after while!
    I have less free time comparing to past years, but the passion still moves things forward.

    Eros, thanks Did you tested it on ATi?
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 7 64bit - Intel Core 2 Duo T6600 @ 2.2GHz - 4 GB RAM - NVIDIA GeForce G210M 512MB
    Windows 8 64bit - Intel Core i5-3350P @ 3.1GHz - 8 GB RAM - NVIDIA GeForce GT640 3GB

  6. #6
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    50
    Posts
    8,184
    Blog Entries
    2
    Rep Power
    10

    Re: Basic example on passing value from ThinBASIC to shader

    Quote Originally Posted by Petr Schreiber
    Eros, thanks Did you tested it on ATi?
    Yes. On "ATI Radeon Mobility X1600 512Mb"
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  7. #7
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    6,795
    Blog Entries
    3
    Rep Power
    693

    Re: Basic example on passing value from ThinBASIC to shader

    Thanks,

    great to know GLSL works reliably there!
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 7 64bit - Intel Core 2 Duo T6600 @ 2.2GHz - 4 GB RAM - NVIDIA GeForce G210M 512MB
    Windows 8 64bit - Intel Core i5-3350P @ 3.1GHz - 8 GB RAM - NVIDIA GeForce GT640 3GB

  8. #8
    Nice tiny shader variable exampler good job.

    There is only one mistake in sub Car_Render()
    Looks like on code line 212 there are one tbgl_PopMatrix() without a tbgl_PushMatrix() in front.

    Internal it would be end in an OpenGL error "matrix stack underrun".
    (more harmless as an stack overrun)

    Joshy
    (Sorry about my bad English.)

  9. #9
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    6,795
    Blog Entries
    3
    Rep Power
    693
    Good catch, fixed.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 7 64bit - Intel Core 2 Duo T6600 @ 2.2GHz - 4 GB RAM - NVIDIA GeForce G210M 512MB
    Windows 8 64bit - Intel Core i5-3350P @ 3.1GHz - 8 GB RAM - NVIDIA GeForce GT640 3GB

Posting Permissions

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