Can GLSL read properties?


I’ve adapted the sepia script to produce night vision. What I want is user input, so if the user presses, say, alt+up, the night vision power increases, and vice versa. So if you press up, the property named “Night Vision” has 1 added. The script reads that and changes the nightvision accordingly. Is this possible with GLSL? I sure don’t want another text file for every amount of power for nightvision!

add this to script -
uniform float NightVision;

link the script to an object, add “NightVision” property and change the value with Logic Bricks

ask if more detailed explanation is needed

The simple answer is: Yes, GLSL shaders can read object properties. You can use variables in both screen filters as well as object shaders. Seeing as you’re using a modified version of the sepia script, I’ll assume you want to know how to do it with screen filters. It is actually very simple. Give the object that runs the night vision filter a variable. We’ll call it “NightVision” Now, at the top of the night vision text file, put:

uniform float NightVision;

Now you’re all set to use it in your filter. Once you have implemented the variable within the night vision filter, you can simply connect some keyboard sensors to some property actuators which increase or decrease the value of the object’s variable upon a key press. The value will be updated in the filter.

If you have any more questions or want to know how to set it up for shaders applied to individual objects, feel free to ask.

Hope that helped!

EDIT: Ooops! He beat me too it:)

Ok, so a Float property, right? So, if I have the color ramps (rgb) as

0, x, 0


x = uniform float NightVision

would it take the number from the NightVision property and apply it to the color ramp?

You must first declare the variable

uniform float NightVision;

at the top of the filter, above the “main” function. After that, you are free to use its value within the “main” function.

Ok, thanks, I’ll try it (I can’t right now, graphics card can’t support it on this comp).

Ok, well, here is a small example I put together using the bloom shader. Use the up, down, left, and right arrows and see how they affect the filter. There are two variables. One adjusts the power of the bloom and one adjusts its “visibility” They are controlled via the “power” and “bloom” properties of the camera.


bloomTest.blend (141 KB)

Thanks so much! It works! But I’ve run into another problem, when really bright, it just becomes super pure green, no white, like in real nightvision. Does anyone know how I can work around this? Sorry, I’m a neb when it comes to GLSL, lol.


Nevermind. Got it! Thanks guys!!


The doorway into the realm of hardcore graphical coders.

Mweeble! panics I think I need a game object… .~.

Sorry for having no input, =P But may I ask a slightly related question.
GLSL looks a lot like C++ to me. Can someone clarify exactly what GLSL is, in terms of language? Compiled/interpreted/somewhere inbetween? Is the compiler simply limited to certain syntaxes, which let you define vector/matrix operations and buffer accesses/functions? And are the vector “library” classes (vec3 etc) built-into the language?

Finally, if it IS semi-compiled… here’s the related part. Can someone explain how it is compiled from Python, and how it accesses a python-based variable?

Im not that experienced in GLSL, but this link may help -
Under the BLG module.

@Raderium… you can find out a lot more about GLSL through Google… it is based off other languages. .there is a compiler…it even gives you error messages… in blender you can see them in the prompt window… and there are a whole bunch of vectors classes amongst other things… there are free apps you can dld to write your shader scripts and test them out before dumping them in blender or which ever game engine you like to use…