Jump to content

[1.11.2] Create Fog


MrObsidy24

Recommended Posts

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)?

Link to comment
Share on other sites

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 by MrObsidy24
Link to comment
Share on other sites

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 by V0idWa1k3r
Link to comment
Share on other sites

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:

 

2017-05-28_10.23.38.png

Edited by MrObsidy24
Link to comment
Share on other sites

	    @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 by MrObsidy24
Link to comment
Share on other sites

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.

2017-05-28_10.23.38.png

Edited by MrObsidy24
Picture
Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.