Converting between FogStart/End to using the Blindness factor Iris uses

Hey! I'm working on a mod that uses some fog rendering features to achieve a limited view range and want it compatible with Iris shaders. Hedge hog pointed me towards the Blindness value that Iris hardcodes for use as a Uniform in shaders rather than using the normal vanilla Fog values. I'm attempting to replicate what I've achieved with fog with shaders by conditionally injecting my own blindness values into getBlindness. I was curious if there's some sort of calculation that could be used to convert from FogStart/End to a blindness value that would allow me to dynamically adjust the radius as needed and have it at least somewhat match the non-shader version of the fog. I'd appreciate any guidance that could be given! Ideally I'd also like to reduce the fog alpha, but given that Iris doesn't seem to have any sort of FogColor vec4 uniform that I'm immediately seeing, I'm guessing that won't be possible. Thanks in advance for the advice!
32 Replies
IMS
IMS17mo ago
assuming you haven't found anything yet Iris does have a fog color uniform, it's vanilla's there's just no guarantee shaders will use it the way you want it to be used either way, this seems to be the way most shaders use blindness
HellionGames
HellionGamesOP17mo ago
That's true, and they don't seem to, since I am setting the values I want on it. That said, that's my secondary issue here. Since that's shader dependent, I don't mind giving up that functionality. I'm more curious about a conversion between the radius of FogStart/End and Iris' Blindness float
IMS
IMS17mo ago
void DoBlindnessFog(inout vec3 color, float lViewPos) {
float fog = lViewPos * 0.3 * blindness;
fog *= fog;
fog = 1.0 - exp(-fog);

fog = clamp(fog, 0.0, 1.0);
color = mix(color, vec3(0.0), fog);
}
void DoBlindnessFog(inout vec3 color, float lViewPos) {
float fog = lViewPos * 0.3 * blindness;
fog *= fog;
fog = 1.0 - exp(-fog);

fog = clamp(fog, 0.0, 1.0);
color = mix(color, vec3(0.0), fog);
}
HellionGames
HellionGamesOP17mo ago
Oh I see, they get to choose how to use the blindness value as well. I appreciate the direction!
IMS
IMS17mo ago
another usage is this
HellionGames
HellionGamesOP17mo ago
Interestingly, that function there entirely ignores any sort of FogColor uniform lol. They just hard set it to black
IMS
IMS17mo ago
vec3 light = vec3(1.0 - blindness);
color = color * vec4(light,1);
vec3 light = vec3(1.0 - blindness);
color = color * vec4(light,1);
(this isn't how it should be used fyi)
HellionGames
HellionGamesOP17mo ago
Interesting! I appreciate the direction. It sounds like I'll probably just have to do a rough approximation for the effect and then just recommend turning shaders off while playing my gamemode
IMS
IMS17mo ago
probably yeah
HellionGames
HellionGamesOP17mo ago
You've been a lot of help both here and over in the Sodium Discord! I appreciate it! I feel like I've gotten to a point where there's at least no advantage to having shaders, just trying to avoid a disadvantage now. Sounds like Shaders may pose a slight disadvantage just as nature of having to be an approximation rather than exact. But that's fine with me since it's easy enough to turn them off for the short time they'd play the game So I've actually talked to a shader dev, and they say that Iris' FogColor uniform is a vec3 rather than Vanilla's vec4. Is this true, and if so, why? Would it be something Iris could update? It doesn't really make sense to me, personally, to use a Vanilla uniform like that but restrict down the values. Any advice on it would be appreciated!
IMS
IMS17mo ago
the optifine spec defines fogColor as a vec3 however, there is also gl_Fog.color which is a vec4
HellionGames
HellionGamesOP17mo ago
Ah gotcha, so there's access to both for shader devs?
IMS
IMS17mo ago
The Optifine spec goes back to 2011, and we can't change anything of it
HellionGames
HellionGamesOP17mo ago
Yeah, that's totally fair!
IMS
IMS17mo ago
so gl_Fog.color is basically just a workaround (there's one important note; the shader must be on the compatibility profile for gl_Fog to work, most shaders are though)
HellionGames
HellionGamesOP17mo ago
I appreciate all the help! A friend reached out to the Complementary Reimagined devs and they seem to be willing to use the FogColor in their shaders rather than a hardcoded vec3(0.0) and alpha 1, so that would be awesome even if just a shader dev or two would make the switch over! Who knows, maybe I'll define a new standard where most use the FogColor! It adds a lot of modded compat support without changing core functionality!
IMS
IMS17mo ago
actually hm i might be able to do something gl_Fog.color is... it's bad
HellionGames
HellionGamesOP17mo ago
I see...
IMS
IMS17mo ago
I'll see if i can change fogColor without breaking packs i think i can
HellionGames
HellionGamesOP17mo ago
That would be awesome!
IMS
IMS17mo ago
[06:34:31] [Render thread/ERROR] (Iris) [sky_basic] Wrong uniform type for fogColor: Iris is providing VEC4 but the program expects VEC3. Disabling that uniform.
ok it was not happy lemme see if i can bypass this
HellionGames
HellionGamesOP17mo ago
Would it be basically possible for anything that expects it as a vec3 to simply chop off the last value? That seems jank, but nothing Vanilla actually changes alpha value. It would reduce compat if things don't change to expect a vec4, but it could save errors
IMS
IMS17mo ago
this is actually possible in normal opengl iris just doesn't expect that so i'm making new code to let that happen
HellionGames
HellionGamesOP17mo ago
Oh sick! You're awesome! Thank you so much!
IMS
IMS17mo ago
nevermind this won't work... I'll see what I can do
For all other uniform types loadable with Uniform* commands, the command
used must match the size and type of the uniform, as declared in the shader, and no type conversions are done. For example, to load a uniform declared as a vec4, Uniform4f{v} must be used, and to load a uniform declared as a dmat3, UniformMatrix3dv must be used.
HellionGames
HellionGamesOP17mo ago
Ah I see. It forces it to be exactly the right size. Darn...
IMS
IMS17mo ago
so yeah they'd probably need to use gl_Fog.color which should still work it's just old
HellionGames
HellionGamesOP17mo ago
That's fair! I'll let them know. Is there a particular thing about it that makes it bad? I'd guess it would just use the values from the RenderSystem, no? What can make a vec4 "bad"?
IMS
IMS17mo ago
gl_Fog is a fixed-function concept, meant for 1.16 and earlier Iris and Optifine use patching tools to make it work in modern versions
HellionGames
HellionGamesOP17mo ago
Ah, I see. That makes sense. Darn. Well, if there's ever a time to make a breaking change in the future... haha! Thanks for all your help though! I'll pass this info on!
IMS
IMS17mo ago
no problem, you can also probably just talk to them here lol (they're emin on this server)
HellionGames
HellionGamesOP17mo ago
Oh yeah, I just DMed them lol. My friend reached out last night. I'll just link them this thread so they can read through themselves since they're already here Interacted with Emin a bit more and they said that apparently Optifine sets incorrect values on gl_Fog.color, so they don't want to use it since it'll break the blindness effect with versions of Optifine that do that. RIP to shader support
Want results from more Discord servers?
Add your server