This is a MonoGame 3.8.4 sample that demonstrates how to implement a lens flare effect using occlusion queries to hide the flares when the sun is hidden behind the landscape.
- Lens Flare Effect: Visual lens flare effects that appear when looking at the sun
- Occlusion Queries: Smart occlusion detection to hide flares when the sun is blocked by terrain
- 3D Terrain: Sample 3D terrain rendering
- Cross-Platform: Supports multiple platforms through MonoGame
- Windows (DirectX)
- DesktopGL (OpenGL - Windows, Linux, macOS)
- Android (OpenGL ES)
- iOS (OpenGL ES)
- .NET 8.0 SDK or later
- For Android development: Android SDK with API level 21+
- For iOS development: Xcode and iOS SDK 11.0+
- Open
LensFlare.slnin Visual Studio - Select the desired platform project (Windows, DesktopGL, Android, or iOS)
- Build and run using F5
-
Open the project folder in VS Code
-
Use Ctrl+Shift+P and run tasks:
- Build Windows:
Tasks: Run Task→build-windows - Build DesktopGL:
Tasks: Run Task→build-desktopgl - Build Android:
Tasks: Run Task→build-android - Run Windows:
Tasks: Run Task→run-windows - Run DesktopGL:
Tasks: Run Task→run-desktopgl
- Build Windows:
-
For debugging, use F5 or Ctrl+F5 to launch the configured debug sessions
dotnet build LensFlare.Windows.csproj
dotnet run --project LensFlare.Windows.csprojdotnet build LensFlare.DesktopGL.csproj
dotnet run --project LensFlare.DesktopGL.csprojdotnet build LensFlare.Android.csproj
# Deploy to connected Android device/emulator:
dotnet publish LensFlare.Android.csproj -f net8.0-androiddotnet build LensFlare.iOS.csproj
# Deploy requires Xcode and connected iOS device or simulator- Arrow Keys / WASD: Move camera around the scene
- Mouse: Look around (if mouse controls are implemented)
- Gamepad: Use gamepad for movement and camera control
LensFlare/
├── Core/ # Shared game logic and components
│ ├── Game.cs # Main game class
│ ├── LensFlareComponent.cs # Lens flare effect implementation
│ └── Content/ # Shared content (textures, models)
├── Platforms/ # Platform-specific code
│ ├── Windows/ # Windows-specific entry point
│ ├── DesktopGL/ # DesktopGL-specific entry point
│ ├── Android/ # Android-specific code and manifest
│ └── iOS/ # iOS-specific code
├── bin/ # Build output
├── obj/ # Build intermediates
├── *.csproj # Project files
└── LensFlare.sln # Visual Studio solution file
This sample demonstrates:
- MonoGame 3.8.4: Modern SDK-style project format
- Cross-platform development: Single codebase, multiple platforms
- GPU Occlusion Queries: Hardware-accelerated visibility testing
- 3D Graphics: Model loading, texturing, and rendering
- Component-based architecture: Clean separation of concerns
This sample is based on the original Microsoft XNA Community Game Platform samples and has been updated for MonoGame 3.8.4.
Feel free to contribute improvements, bug fixes, or platform-specific optimizations through pull requests.