kirides / GD3D11

D3D11-Renderer for Gothic and Gothic 2
GNU General Public License v3.0
200 stars 18 forks source link

Render fog zones in Gothic 1 #153

Closed ThielHater closed 7 months ago

ThielHater commented 7 months ago

This PR will modulate the fog density in Gothic 1 based on the far Z value. The behaviour of the renderer with Gothic 2 is not changed.

The fog in Gothic 1 is not that complex. There is no override flag or -color, compared to Gothic 2. Only the far Z value is changed, limiting the maximum view distance and leaving the rest to D3D. That version of zEngine does not even calculate the color but I wrote a Union plugin to fix that.

I did not module HF_WeightZNear and HF_WeightZFar as it was not beneficial to the graphics, the default values are fine.

The change was tested on Gothic 1 inside and outside of a fog zone, with and without rain as well as with and without my additional plugin. Everything looked fine.

kirides commented 7 months ago

Am i seeing this correctly? the new behavior is, rain-fog in G1 no longer uses colors, but only grays out?

OLD fog_old

NEW fog_new

NEW | OLD grafik

ThielHater commented 7 months ago

I did not notice that. Looking at the code, that change was not intentional and I guess it stems from using the fog color Gothic calculated.

kirides commented 7 months ago

Could you point me towards the visual changes that should happen?

I can't really make out what has changed. Maybe i'm testing wrong places?

for G1 i stood right in the Swamp camp, where there is colored fog, what i think should be a "fog zone" as well as toggled rain (marvin console zstartrain 0)

What do i need to look at to observe the changes?

ThielHater commented 7 months ago

My bad, I probably should have given a little more explanation.

In Gothic 1 there are just two fog zones, you can find them if you search for zCZoneZFog in World.zen. The default fog zone has a view distance of 15000 units, the fog zone in the Psi Camp has 8000 units. However, the effect is somewhat subtle. You may have a look at this video of the original renderer:

https://github.com/kirides/GD3D11/assets/4657476/5c9ea22a-ae74-4ec2-86ac-46d22cec8c19

If you look at the tree right infront, it gets revealed more and more as the camera gets closer but at about 5 seconds it gets covered by the fog again. That is when the camera enters the fog zone and the view distance (also know as far Z value) is reduced. Then the tree gets revealed again, as we are getting closer all the time.

Now here is how it looks with the version of the D3D11 renderer, which I want to merge:

https://github.com/kirides/GD3D11/assets/4657476/48cc3653-54b8-444c-84db-3da1255759d5

Gothic 1 does not respect the color of the fog zones. Instead it uses the value of SKY_OUTDOOR.zDayColor0 from Gothic.ini for most of the day and interpolates between a list of pre-defined colors, depending on the time of the day. I wrote a Union plugin to calculate the fog color like Gothic 2 does, taking in base color, time of the day and fog zones the player is in, and writing the value to the corresponding address in memory. (By the way, with this change the setting FogColorMod will loose effect for Gothic 1 and the value from zEngine will be used.) As the color of the fog zone in the Psi Camp is 120/120/120, it looks like this:

https://github.com/kirides/GD3D11/assets/4657476/894eb8e1-142e-4238-b2dc-e573a04a5449

I am not a hundred percent happy with the result. With the D3D11 renderer, the resulting fog color is darker than the original because the shader mixes it with a value coming from the atmospheric scattering. Do you have an idea?

Of course things get more interesting, when a mod has it's own fog zones with different colors. 😅

ThielHater commented 7 months ago

One more thing: Gothic 1 uses 95/95/95 as fog color during rain, which is a neutral and not a warm gray. I am not concerned about that, but you raised the question. 😄

ThielHater commented 7 months ago

Please go ahead.

ThielHater commented 7 months ago

By the way, do you plan a new release? I noted that assimp was updated for example. At first the game crashed because I had an older version.

kirides commented 7 months ago

I do not in the near time, due to having no time for validating that all changes are OK.

People raised some issues about crashes in Chronicles of Myrtana Archolos, which someone has to check if that's on the Renderer or just because the game/mod keeps leaking memory.

For now all changes are automatically included, without complete validation, in the nightly release.