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
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
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
Oh I see, they get to choose how to use the blindness value as well. I appreciate the direction!
another usage is this
Interestingly, that function there entirely ignores any sort of FogColor uniform lol. They just hard set it to black
(this isn't how it should be used fyi)
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
probably yeah
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!
the optifine spec defines
fogColor
as a vec3
however, there is also gl_Fog.color
which is a vec4Ah gotcha, so there's access to both for shader devs?
The Optifine spec goes back to 2011, and we can't change anything of it
Yeah, that's totally fair!
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)
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!
actually
hm
i might be able to do something
gl_Fog.color is... it's bad
I see...
I'll see if i can change
fogColor
without breaking packs
i think i canThat would be awesome!
[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
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
this is actually possible in normal opengl
iris just doesn't expect that
so i'm making new code to let that happen
Oh sick! You're awesome! Thank you so much!
nevermind this won't work...
I'll see what I can do
For all other uniform types loadable with Uniform* commands, the commandused 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.
Ah I see. It forces it to be exactly the right size. Darn...
so yeah they'd probably need to use gl_Fog.color
which should still work
it's just old
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"?
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 versionsAh, 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!
no problem, you can also probably just talk to them here lol
(they're emin on this server)
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