Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

D3D9 atmosphere remake (WIP) #324

Merged
merged 57 commits into from
Dec 31, 2022
Merged

D3D9 atmosphere remake (WIP) #324

merged 57 commits into from
Dec 31, 2022

Conversation

jarmonik
Copy link
Contributor

@jarmonik jarmonik commented Dec 11, 2022

-Complete rework of atmospheric rendering and some updates to planet rendering in general.
-Fixed and re-enabled shader cache feature for faster loading.
-Added a Sun glare which can be disabled form setup and adjusted/tuned from graphics controls dialog.
-Added a enable/disable control for the irradiance/dynamic ambient light feature.
-Screen space depth/normal buffer is now available for future SSAO implementation.
-Fixed asteroid/comet rendering bug reported in the forums.

Made tests to verify correct operation of the math routines.
Added WorldBillboard() routine to Sketchpad to improve planetarium mode drawing.
Fixed anomalous wave effects at day/night terminator.
…ch seem to work well enough. Restored celestial sphere visibility through atmosphere. Started working on atmospheric haze on vessels and base structures.
@mschweiger
Copy link
Collaborator

mschweiger commented Dec 11, 2022

On launching a scenario, I get a message box Metalness.fx(279,2): error X3004: undeclared identifier 'cAmbient' on top of the splash screen. (x86 and x64 builds, all scenarios). Nothing shows up in log file. Last log entry is D3D9: [3DDevice Initialized]

Edit: With a debug build, I do get some info in Orbiter.log:

000026.265: D3D9ERROR: C:\Source\Orbiter_devel\Orbiter\OVP\D3D9Client\D3D9Effect.cpp Line:350 Error:-2147467259 D3DXCreateEffectFromFileA(pDev, name, macro, 0, D3DXSHADER_NO_PRESHADER|D3DXSHADER_PREFER_FLOW_CONTROL, 0, &FX, &errors)
000026.266: D3D9ERROR: Effect Error: Metalness.fx(279,2): error X3004: undeclared identifier 'cAmbient'

Edit 2: This may be a shot in the dark, but Metalness.fx defines float3 cAmbient conditionally if _ENVMAP is defined, but accesses it outside the condition. What happens if _ENVMAP is not defined?

@mschweiger
Copy link
Collaborator

I temporarily patched up the previous problem to get a bit further. I now get a message box Failed to compile a shader - [...]\NewPlanet.hlsl(486,9): warning X3571: pow(f, e) will not work for negative f, use abs(f) or conditionally handle negative values if you expect them.
Am I using a wrong version of the runtimes? I didn't have any problems with the previous D3D9 client version.

@jarmonik
Copy link
Contributor Author

Thanks for the reports. Looks like I forget to re-run the tests with lot of features disabled after making modifications. It's normal for the "pow" instruction to raise a warning if not secured from negative input. The runtimes should be correct if it gets that far, no changes in runtime requirements.

@jarmonik
Copy link
Contributor Author

Looks like there is a problem with shader cache. When a shader is loaded from a cache, feature on/off toggles have no effect since they are applied during compiling. How can I overlook something like this.

@mschweiger
Copy link
Collaborator

The latest commits are fixing the reported issues for me. Thanks! For what it is worth, I have attached the Earth atmosphere settings I came up with, but I agree that there probably isn't a single configuration that works for everyone, since apart from subjective preferences this is also a matter of monitor/graphics driver characteristics and settings.
Earth.atm.cfg.txt

MicroTextures[x.file] = x.pTex;
}
else {
LogErr("Failed to read microtexture [%s] for [%s]", file_path, body.first);
Copy link
Contributor

@schnepe2 schnepe2 Dec 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

	LogErr("Failed to read microtexture [%s] for [%s]", file_path, body.first.c_str());

LogErr("Failed to read microtexture [%s] for [%s]", file_path, body.first.c_str());
would be correct as body.first is std::string...
(as noted here https://www.orbiter-forum.com/threads/d3d9client-development.16787/post-604331)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the report. This should be fixed.

@mschweiger
Copy link
Collaborator

mschweiger commented Dec 12, 2022

Setting ShaderCacheUse = 1 in D3D9Client.cfg causes a crash for me. Unfortunately this seems to be the default setting if D3D9Client.cfg is missing.
Also, there is a D3D9Client.cfg in the root source directory, but it doesn't actually seem to be used. Can it be removed from the repository? This would also help to keep the root directory clean.

The crash was caused by NULL values for the bytes read/bytes written parameters in the ReadFile and WriteFile calls in D3D9Util.cpp. According to the Windows API documentation, these parameters must not be NULL for Windows-7, and I am slightly embarrassed to say that I am currently debugging on a Windows-7 machine. I have committed a fix to provide Windows-7 compatibility.

mschweiger and others added 4 commits December 12, 2022 23:42
…iteFile calls and lpNumberOfBytesRead parameter in ReadFile calls (D3D9Util.cpp). This ensures Windows-7 compatibility.
…isabled shader cache by default. Disable Orbiter log messages regarding cache use.
@schnepe2
Copy link
Contributor

Regarding the ShaderCacheUse = 1|0 in D3D9Client.cfg.
When it's enabled, it creates the Cache/Shaders folder if not present. Is this the path we like to use? I mean The Cache folder[*].

There are several AddOns that would like to use such a folder for non-volatile storage. Currently only the root folder was mainly used for storing configurations or data-files.

I like the name Cache, but maybe there's a better name for this (soon to be filled with "garbage") folder?
Temp does not feel right either.

So this is just a Request For Comments.


[*] D3D9Client should maybe use a sub-folder like Cache/D3D9Client/Shaders, so the "user" of the files is more clear.
The guideline should then be something like Cache\<AddonName>\

@jarmonik jarmonik merged commit c715f70 into main Dec 31, 2022
@jarmonik jarmonik deleted the d3d9_atmosphere_remake branch January 1, 2023 02:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants