Posted May 27, 20178 yr So I am creating a Mod that acts similar to weather2 by Corosus and the thing I ask for is the following: When underneath a storm, I want the player to experience fog. I have no idea how to to this (I tried the EntityViewRenderEvent.FogDensity / FogColor, this just makes the sky appear black and white). the method EntityRender.setupFog() method is private so I cannot use that. Anybody knows how to setup fog (preferrably with color)?
May 28, 20178 yr FogDensity/FogColors events work just fine for me. How exactly have you tried using them?
May 28, 20178 yr Author 5 hours ago, V0idWa1k3r said: FogDensity/FogColors events work just fine for me. How exactly have you tried using them? I implemented them like this: @SideOnly(Side.CLIENT) @SubscribeEvent public void onFogDensityRender(EntityViewRenderEvent.FogDensity event){ event.setDensity(Constants.fogDensity); event.setCanceled(true); } @SideOnly(Side.CLIENT) @SubscribeEvent public void onFogColorRender(EntityViewRenderEvent.FogColors event){ event.setRed(255 / Constants.fogColor.getRed()); event.setGreen(255 / Constants.fogColor.getGreen()); event.setBlue(255 / Constants.fogColor.getBlue()); event.setCancaled(true); } Edited May 28, 20178 yr by MrObsidy24
May 28, 20178 yr 11 minutes ago, MrObsidy24 said: event.setCancaled(true); cancaled? That would not even compile. You do not need to cancel FogColors event. Only FogDensity. What is Constants.fogColor ? Why are you dividing 255 by it's variables? rgb are float ranges[0-1], and unless Constants.fogColor contains floats/doubles that are greater than 255 it is not going to work and is going to set the color to either white(if they are less than 255) or black(if getRed/green/blue returns not a float/double and is greater than 255) Edited May 28, 20178 yr by V0idWa1k3r
May 28, 20178 yr Author 8 minutes ago, V0idWa1k3r said: cancaled? That would not even compile. You do not need to cancel FogColors event. Only FogDensity. What is Constants.fogColor ? Why are you dividing 255 by it's variables? rgb are float ranges[0-1], and unless Constants.fogColor contains floats/doubles that are greater than 255 it is not going to work and is going to set the color to either white(if they are less than 255) or black(if getRed/green/blue returns not a float/double and is greater than 255) The event.setCanceled(); was a typo mistake on this forum (the code does not have this mistake). (it says canceled in the code) Constants.fogColor is a ljwgl color which stores the red/green/blue as ints as values 0-255 I just realized my mistake. I divide the 255 by the value, not the value by 255. And I am in maths AP. Oops. I'll try that. EDIT: just realized that FogColor() is not cancelable. Also, this is what the fog looks like on my screen: Edited May 28, 20178 yr by MrObsidy24
May 28, 20178 yr If it is storing them as int values do not forget to cast them to floats/doubles before you divide by them otherwise java will perform an int/int division that has no decimal part and will get auto-rounded to 0(or 1, if the variable is 255)
May 28, 20178 yr Author I'll try that. I edited my post above to show you how the fog looks EDIT: Didn't work, result still the same as above. Edited May 28, 20178 yr by MrObsidy24
May 28, 20178 yr Author @SideOnly(Side.CLIENT) @SubscribeEvent public void onFogDensityRender(EntityViewRenderEvent.FogDensity event){ event.setDensity(Constants.fogDensity); event.setCanceled(true); } @SideOnly(Side.CLIENT) @SubscribeEvent public void onFogColorRender(EntityViewRenderEvent.FogColors event){ event.setRed((float) Constants.fogColor.getRed() / 255); event.setGreen((float) Constants.fogColor.getGreen() / 255); event.setBlue((float) Constants.fogColor.getBlue() / 255); } EDIT: Another Edit. So if I increase the fog density, everything works good again and I see fog. However, if the fog density is 0, i get that weird bar on the sky which is colored like the fog. Do you know how to fix that? Edited May 28, 20178 yr by MrObsidy24
May 28, 20178 yr I do not experience any issues with your implementation. What is 3 minutes ago, MrObsidy24 said: Constants.fogDensity ? It is supposed to be a float of [0-1] range (0 - no fog, 1 - pretty much only fog is visible, you can barely see the world)
May 28, 20178 yr Author 47 minutes ago, V0idWa1k3r said: I do not experience any issues with your implementation. What is ? It is supposed to be a float of [0-1] range (0 - no fog, 1 - pretty much only fog is visible, you can barely see the world) Constants.fogDensity is 0f. EDIT: The picture below is with fogDensity set to 0f. Edited May 28, 20178 yr by MrObsidy24 Picture
May 28, 20178 yr Well, 0 will pretty much disable the fog - and that is what you are seeing to be fair. I am not sure what causes the sky color issue, it might be something else as I do not experience it with your code.
May 28, 20178 yr Author Weird. Do you know if there is any other way to create fog? Edited May 28, 20178 yr by MrObsidy24
May 28, 20178 yr Why do you want your fog density to be zero? That's essentially the same as there being no fog (minus the buggy sky), so if you want density zero why not just remove the fog?
May 28, 20178 yr So, I've investigated the issue. I have managed to achieve something somewhat similar. In fact, I've achieved pretty much the same picture of yours! The issue is very obscure, and it lies within the way the game renders it's sky. Or, rather, within the fact that it only properly colors the top half of the sky only (+ sunrise/sunset gradients ofc) and kinda leaves the rest for the fog. Usually the fog is dense enough and matches the sky color to hide the transition from 'skybox' if you could call it a skybox to a solid color. However if you remove the fog and just set the color... Well you get the background color of the color you've specified, but the sky is a different color! Thus you see this result. The only reason I was not able to replicate your issue is because I've had my own sky renderer enabled that eliminates the issue by rendering a propper-ish skybox... I am not sure if much can be done tbh. Even custom fog rendering with GL would not help here. You can however hide the issue by matching the color of the fog with the color of the sky - it is available at World::getSkyColor. Or do not touch the color event at all. That would work as by default it matches the color of the sky. (pretty similar to what Jay suggested) Or make the fog relatively dense with your color so it hides the sky. Apart from that the sky color is hardcoded and I do not see any hooks to modify that... The biome can return a custom sky color but there are no events in place to affect vanilla biomes. A WorldProvider can return a custom color implementation but yet again - no events... You could implement your own sky renderer but it will break with any mod that does the same(although something like this might be possible in the future, see #3665) I could be missing something though.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.