Making Shader Progress...?
I think I'm making progress on the OpenFL+GLSL shaders. It was a close call, but by the end of the day, I finally wrote my own normal map vertex and fragment shaders, and they seem to be displaying like they should.
If nothing else, I'm learning OpenGL, GLSL, and a lot about 3D display math. For example, one thing my previous attempts did wrong was to use deprecated OpenGL uniforms. Namely, things like gl_Normal, gl_NormalMatrix, gl_ModelViewMatrix, etc. Silly me thought, "The shader already has those values? That's really handy!"
No, no it doesn't. Instead, I needed to feed my shader these values, or else piece them together within the shader. So when I finally figured that out, I was able to make some headway on a shader that uses actual data instead of unknown values.
And the result?
So what we're looking at here is a 512x512 plane with a cushion texture applied to it, and a light where the crudely-drawn white starburst is. This cushion texture has a "normal map" (which is a texture that sort of defines surface bumpiness), and the light highlights and shadows the bumpy parts.
A few days ago, I had a version of this working almost flawlessly, with one drawback: it didn't change if the cushion square moved around or rotated. The lighting would always come from the same direction (like it was drawn permanently onto the cushion.)
This newer shader updates the highlights and shadows based on both the position and rotation of the cushion. And this is important because I'd like to try ship parts that can be rotated and placed and have the lighting react accordingly. Without this, I'd probably have to have 4 separate copies of each ship part, with normal maps for each rotation (costly/tedious to draw, and uses lots of memory).
Now, this isn't perfect. For example, there's an area directly underneath the light that should probably be lit, but seems to be in shadow. Also, the "peaks" of the cushions seem to have a rough texture to them. I'm thinking this may be a problem with the way I'm combining cushion color with the light component, or else the light is so close to the cushion that individual threads in the cushion material are causing shadows.
It's a start. I've been "wasting" a lot of time on this, but I'm still optimistic the outcome will be worth it. Especially since figuring this out now should mean I don't have to mess with it much again later, as it'll be the basis for most lighting effects used in the prototype. Just gotta figure this beast out...