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!
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.
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.
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.
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?
@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…