Shaders and other questions

Have a question, suggestion, or comment about Aleph One's features and functionality (Lua, MML, the engine itself, etc)? Post such topics here.

Shaders and other questions

Post Jan 3rd '19, 23:38

Is there any documentation for how to develop shaders for AlephOne? Or is a shader a universal thing, and there's nothing AlephOne specific about writing one? I really don't know much of anything about them.

The specific problem I'm looking for a solution to is give the player infravision, but also limit their view distance. Infravision seems to disable level lighting, so you can see forever. If I turn fog on, it kind of works but everything ends up super dark, even up close.

I guess first I should confirm there's no existing way to make fog work differently so that it doesn't have any effect up close, and then quickly drops to pitch black. Or is there a way to make infravision respect level lighting?

Assuming I knew how to write one, would it be possible to achieve this with a shader plugin? Can it detect when infravision is active?
User avatar

Wrkncacnter

Post Jan 4th '19, 02:26

The shaders are written in GLSL. What you are describing would be easy to implement, but it would depend on whether the shader can detect if infravision is on or not. What does A1 expose that you could infer from?

Here’s what the sprite shader has available:

uniform sampler2D texture0;
uniform float glow;
uniform float flare;
uniform float selfLuminosity;
varying vec3 viewDir;
varying vec4 vertexColor;
varying float FDxLOG2E;
varying float classicDepth;


One other approach is to still use fog, but change the shader such that the fog doesn’t start until some distance beyond the viewer. The wall and sprite shaders have all the info they need for that (the fragment depth is in gl_FragCoord.z).
User avatar

TrajansRow

Post Jan 4th '19, 02:36

TrajansRow wrote:One other approach is to still use fog, but change the shader such that the fog doesn’t start until some distance beyond the viewer. The wall and sprite shaders have all the info they need for that (the fragment depth is in gl_FragCoord.z).

This sounds ideal, since really, I don't need to know whether infravision is active or not. If it's not active, your view distance will be cut short anyway and you'd never even see the fog, due to the level lighting.

So now I guess I just need to see if I can learn GLSL enough to understand what you just said :P. Thanks for the response.
User avatar

Wrkncacnter

Post Jan 4th '19, 02:39

Try adding a constant to the result of exp2(FDxLOG2E * length(viewDir)) where the fogFactor is calculated. You will have to apply the adjustment to any shader that mixes the fog color with the fragColor.
User avatar

TrajansRow

Post Jan 4th '19, 03:35

Wow, this is amazing, thank you! I think this will not only make things look less weird, it will significantly help performance over the hack I was using before.
User avatar

Wrkncacnter

Post Jan 27th '19, 05:29

OK, I thought I had this working, and it seems to work for windows and linux, but crashes on mac.

I changed this:
float fogFactor = clamp(exp2(FDxLOG2E * length(viewDir)), 0.0, 1.0);

to:
float fogFactor = clamp(exp2(FDxLOG2E * (length(viewDir)) + 12), 0.0, 1.0);

This seemed to make it so that I could still dynamically set the fog.depth with lua and the distance before fog kicks in changes. This is perfect for what I need. However, I don't totally understand this code and it apparently causes it to crash on macOS. I had originally done what you suggested and added the constant to the whole result of exp2(FDxLOG2E * length(viewDir)), but that didn't seem to do what I wanted. It looked like it might just be making things dimmer overall, but I can't say for sure.

Does anyone understand why this crashes on macs? Am I doing something really dumb?
User avatar

Wrkncacnter

Post Jan 27th '19, 13:34

GLSL is strict about data types. Try using 12.0 instead of 12.

I think Aleph One should report shader errors when they occur, instead of exiting.
User avatar

TrajansRow

Post Jan 28th '19, 03:24

Hmm, thanks for the suggestion, but it is apparently still exiting out.
User avatar

Wrkncacnter

Post Jan 28th '19, 04:06

Here's a plugin demonstrating the issue. It's working for me in linux. I don't actually have a mac, so it's hard for me to test anything. I'm pretty sure this will cause Aleph One to exit out on a mac.

Any obvious problems with it?
Attachments
PrahblumShader.zip
(4.69 KiB) Downloaded 29 times
User avatar

Wrkncacnter

Post Jan 28th '19, 05:25

The various OpenGL implementations aren't exactly known for their consistency...

In some (or all?) of the shaders, the problem seems to be that the main() function ends with a '};' instead of '}'. If you remove that last semicolon, they should compile fine on Apple's OGL.
User avatar

TrajansRow

Post Jan 28th '19, 05:53

Oh nice, I'm not sure where those ; were coming from in the first place, now that I look at what I was copying the code from. I must have copied and pasted something wrong.

Thanks for taking the time to figure this out, it's working now!
User avatar

Wrkncacnter


Return to Aleph One Discussion



Who is online

Users browsing this forum: No registered users

cron