Implement basic directional shadow CSM with PCF#1252
Implement basic directional shadow CSM with PCF#1252adfriz wants to merge 18 commits intoleezer3:masterfrom
Conversation
|
First off, congratualtions. Faces using transparency aren't quite right yet though- I don't think they're casting shadow at all, but I haven't got as far as debugging it properly. (This is a particularly egregious example- 8 transparent pixels in the whole texture. Transparency shouldn't be used here at all, but I seem to have done so accidentally when building the object....) I've made a small change in the main branch so that faces which declare a transparent color but don't actuallly use it will work correctly, and this should also help general performance a little. With row / column major etc.: |
Thank you leezer3. for that test object i have fix the code related to it.
for that row / column major, i was confused at first... especially i was searching about opengl tutorials but thanks for pointing that out, and at least the shadow works now, need more test though... |
|
When I run by 'mono OpenBve.exe', it crashed. |
|
I haven't yet had a chance to test on Mac (only got an Intel available though), but it definitely will need the most recent commit- GLSL 4.1 is the best it does. A good universal new feature like ths might be an opportunity to drop the old renderer entirely. I considered this a year ago (when adding smoke and the MSTS keyframe animations), but never quite got further than the draft PR thoughts. |
i think the same about old renderer, on my machine on the most route files if i use the old one i get "stable" micro stutter and trying bve5 route drop it to below 40fps |
this one is hard... because im not using linux. but i suspect in the main program the renderer maybe auto fallback to the old renderer... for the object viewer i think you need to change something on the shadow settings, try change the resolution to high and press ok. and if you can see the shadow you can change it back to medium. its known issue on my side, sometimes the object viewer didnt register the shadow settings after rebuilds. can you do full rebuild of the source code please? |
|
Previously, displaying coordinates with the C key caused a crash. It didn't happen this time, so I thought it was a new source code. I downloaded the ZIP file again, rebuilt everything, and tried displaying it in RouteViewer again. I tried various angles, but the shadows didn't appear. |
Apple doesn't like the current build at all. If I disable the GL.GetError, the loading screen background texture is black, but the loading screen works. Going to try this on the desktop in a minute, it's a lot easier to debug things in Visual Studio. |
|
OK, so now I can see things with a proper debugger, the issue is that something you're doing is not compatible with a forwards compatible GL4.1 context. (In other words you're using something that's been deprecated) Shadows are working for me on Windows, but I suspect this is probably related for those who they don't. (I'm guessing, but it may well be dropping to GL2 if the context fails) |
|
Why don't shadows appear when I build and run this link in Release mode on my Ubuntu system...? |
The CSM logs are written to the console (Which i think we should move it to OpenBVE's logging system but that's another topic), so try launching it in the terminal and see what kind of output it gives. Curiously I am getting the following: Couldn't quite tell if it's my fault |
経過時間 00:00:06.74 |
|
Putting that aside, I have been waiting for this feature for many, many years. |
I meant in runtime, when you run the OpenBVE program (i.e. mono OpenBve.exe), or look at the console tab in an IDE while you were running/debugging it. ... Though now that your images load on my side, it doesn't seems to be the same issue (I didn't get any lighting at all and just reverted back as if shadow were turned off) |
|
[CSM] Init failed: [ShadowDepthShader] Compile error (FragmentShaderArb): 0:29(24): error: syntax error, unexpected end of file user@bin_debug$ Addendum: |
|
https://github.com/leezer3/OpenBVE/tree/7c7cb61dc88fb89d5ffd631439c0bebe6d9935a8 |
|
I know what's going on, and it's messy. The line endings are getting messed up, and compiling the shader is throwing a fit as a result. I've built this one locally from the latest on my branch, which fixes the shaders as an embedded resource. I think this one will work on Linux again. I think it might well work OK on Apple too, but would need the shadows enabling manually via the CFG file at the minute. |
|
When I launched OpenBVE using shadow.zip, even with Shadow Resolution set to 4096, it only appeared as a blurred version of 512. Addendum: |
|
I'm not sure why the quality is messed up for you- seems to work here. I've added a GL menu impimentation for the main game this morning, will see about testing on Apple again. Another observation: It's a pity that I don't think there's a way to tell internally what type of object something is, other than whether it's dynamic (animated / train) or not. |
|
Our default light (before modifying with the LightDirection command) is positioned nearly overhead, which gives an even illumination to the scene, no matter which way the camera is rotated. If you're then using 2D (vertical) planes for the majority of your objects, with the light essentially overhead, they can't cast a shadow, no matter which way they're pointing. In this case horizontal planes will still cast shadows, but it very much depends on how the objects in question were designed. A possible way to get around this would be to alter the default light position to something lower in the sky, but that then makes the other lighting 'wrong' to the original. Your route works OK, as you've changed the default light direction. |
That's better, thanks. that empty space can be used for future settings like post processing SSAO, bloom, etc.... |
|
I think so too |
- Add CascadedShadowMap and CascadedShadowCaster to LibRender2. - Implement shadow depth shaders for depth pass rendering. - Update default shaders to support shadow sampling and application. - Add shadow configuration settings (Resolution, Distance, Cascades, Strength) across OpenBVE, RouteViewer, and ObjectViewer. - Update math library with frustum and matrix helper functions. - Add localization for shadow settings in English and Indonesian.
- Converted RouteViewer to a tabbed layout matching ObjectViewer. - Added sun direction sliders (Azimuth/Elevation) to RouteViewer. - Unified shadow resolution and distance values across both viewers. - Made options windows resizable with AutoScroll support. - Changed default shadow resolution to Off and added control enabling logic. - Fixed shadow initialization after route loading in RouteViewer.
- Clamp minimum FOV in shadow bounding sphere calculation to prevent shadows from clipping when zooming in. - Apply dynamic shadow bias directly in the fragment shader to minimize shadow acne and detachment artifacts. - Introduce new Shadow Bias options in the UI for OpenBVE, RouteViewer, and ObjectViewer. - Set the default shadow bias value to 0.000005
Update viewport to Scenery mode before running the shadow pass, preventing the cab's 50m far-clip matrix from incorrectly capping the shadow distance.
- Added AlphaFaces to the CSM shadow pass so cutout objects cast shadows. - Reset LastBoundTexture after the shadow pass to prevent texture bleeding on untextured meshes.
- Added alpha-discard in shadow depth shader to prevent transparent meshes from casting shadows. - Implemented slope-scaled shadow normal bias in fragment shader to cure shadow acne. - Expose Normal Bias settings in OpenBVE, RouteViewer, and ObjectViewer UI/Options. - Support for 4-value RGBA color parsing for legacy and Assimp parsers. Note: shadow bias and shadow normal bias need more tweak.
…ing commmand for objects
- Standardize global default ShadowBias to 0.000050 in BaseOptions. - Set default ShadowResolution to Off across all applications. - Remove hardcoded shadow setting overrides in Object Viewer to respect global defaults. - Implement a 3-column layout in the main Options interface to better utilize screen space when maximized. - Fix UI clipping/gaps in the Options menu by explicitly synchronizing groupbox widths during form resize.
1f8fee8 to
027cf27
Compare
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
I used TFO with an X object use for Bve5's, and while the bridge's shadow is visible in the outer view, the X object itself doesn't have a shadow on the roof. The X object itself has an effect applied, but the object itself doesn't seem to X obj have any other effects. |
|
I think that will fix the X object issues. |
|
It's probably something with my build. Strange thing is I don't think the method it's on about has been touched at all. |
- Added LightAzimuth and LightElevation to Route Viewer options (Save/Load). - Disabled shadow controls in the UI if the current renderer is not compatible (GL 1.2), matching ObjectViewer behavior. - Added a safety check to prevent zero ShadowBias during initialization. - Standardized ShadowStrength string formatting in the options file for consistency.


























Note:
Only tested locally in release and debug builds on windows.
Need further fix, not guaranteed 100% works on all route and trains.
Need more test for linux and macos.