PDA

View Full Version : Basic example on passing value from ThinBASIC to shader



Petr Schreiber
13-09-2009, 12:11
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.

Michael Hartlef
13-09-2009, 14:34
Looks nice! :)

ErosOlmi
13-09-2009, 23:12
Smart, elegant, flicker free, fast, interpreted and ... just 200 lines of code.
:D

kryton9
14-09-2009, 17:10
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!

Petr Schreiber
14-09-2009, 17:37
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?

ErosOlmi
14-09-2009, 17:44
Eros, thanks :) Did you tested it on ATi?


Yes. On "ATI Radeon Mobility X1600 512Mb"

Petr Schreiber
14-09-2009, 17:55
Thanks,

great to know GLSL works reliably there!

D.J.Peters
18-05-2013, 16:34
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

Petr Schreiber
19-05-2013, 09:41
Good catch, fixed.


Petr