One of the most complex tasks in 3D programming in C++ C is shadows in OpenGL and DirectX!Shadows are often confused with shading during development, although together they are responsible for the impression of the 3D landscape. However, shading is much simpler than complex shadow calculations and the decision whether to use mapping or real-time shadow calculation, as well as the question of when what makes sense! Here in this FAQ I will summarize and expand information on the subject of 3D shadows! Contents: 1.) ... The shadow and shading difference Shadow vs Shadow!
|
(Image-1) Shadow vs Shading |
2.) Example 1 shading with tested source code!
The example on the left in the picture: ► OpenGL 2.1 - GLSL shadow cube mapping
The shadow example on the right: ►► OpenGL 2.1 - Fast realistic soft penumbra shadows
Another one by the same author: ►► Software shadow mapping << Quite interesting because it's software ;-)
And: Terrain, BSP tree, frustum culling, sorting, shadow mapping
Info:
I have tested all three projects, you can compile (create) them with any Visual Studio 2008, 2017, ..., even with the old VC 6.0. The "fast realistic .. " crashes, set "Pause = true;" in the source code! The source codes can be downloaded at the bottom of the respective page!
I have tested all three projects, you can compile (create) them with any Visual Studio 2008, 2017, ..., even with the old VC 6.0. The "fast realistic .. " crashes, set "Pause = true;" in the source code! The source codes can be downloaded at the bottom of the respective page!
(Image-2) 3D C++ C shadows in OpenGL! |
3.) The classic Shadow example from OpenGL!
1. Rotating cube with dynamic shadows (also works in color index mode!).
Page ►► OpenGL - Examples Source code: ► scube.c
2. The classic jumping dino with shadow as an example
Page: ► ... opengl.org ...archives ... examples/examples.html Source code: ►► dinoshade.c
3. Another one with *.obj files and shadows! Soft shadows in real time. Press the 'h' key and a help menu will appear. Drag the middle mouse button to rotate the scene.
Download: ► shadow.zip Page: ... www.opengl.org/archives/resources/code/samples/more_samples/
(Image-3) Classic shadow examples with OpenGL! |
X.) Why this page and other links and information about shadows and shading!
The page is regularly updated! There are many on the internet, but the ones selected here are suitable for understanding it and have little ballast! Most of the time you download several MB of source code and it is not suitable for understanding the purpose, how it works, etc.!
►► OpenGL - Why shadows?
►► OpenGL - What are shaders?
►► .. learnopengl.com/Advanced-Lighting/Shadows/Shadow-Mapping
►► ... Super Mario 64 << a few effects and a lot of source code can be used as an example to a limited extent!
Will also be updated!
Random number generator:
►► https://www.shadertoy.com/view/tsf3Dn
►► https://www.shadertoy.com/view/4slGD4
►► https://www.shadertoy.com/view/4ttSWf !
►► https://wiki.delphigl.com/index.php/Shadersammlung !
(Image-4) Shader in OpenGL GLS |
A popular method of generating a custom texture for a heightmap is to combine parts of other "source" textures in such a way that the resulting texture maps directly to the features of the heightmap. For example, a snow texture could be used for the peaks of mountains, a rock texture for elevations not covered in snow, a grass texture for areas below mountains, a sand texture for lower beach areas, and a water texture for the lowest points on the map. This article looks at two ways of combining textures, slicing and blending. Cut sections of textures and stitch them together to create a new texture. Blending, an improvement on slicing, blends the textures together by weighting the color values of the sections based on the heightmap data.
http://jeff.bagu.org/articles/ptg4heightmaps.html#
Also interesting:
https://entwickler.de/online/development/opengl-landschaftsgestaltung-mit-height-maps-co-114982.html
And:
http://shdr.bkcore.com
(Image-5) 3D C++ C shadows in OpenGL and DirectX! |
4.) Here is another program with source code!
This program shows a simple scene lit by a single light. The scene is first rendered from the perspective of the light and the depth values are loaded into a texture. This texture is then projected onto the scene from the perspective of the eye and a comparison is made with the distance from the light. This determines shadowed areas.
This demo implements 8-bit dual texture shadow mapping and a 16-bit version using register combiners. 24-bit hardware shadow mapping is also demonstrated.
►►► http://www.paulsprojects.net/opengl/shadowmap/shadowmap.html !
NVIDIA
►► https://developer.nvidia.com/sites/all/modules/custom/gpugems/books/GPUGems/gpugems_ch12.html
►► https://developer.nvidia.com/sites/all/modules/custom/gpugems/books/GPUGems/gpugems_ch09.html
Info:
Shadow volumes are not ideal for all scenes. The technique involves constructing a 3D volume that encloses all shadows cast by an object. This volume is constructed from the shadow caster's mesh; however, some shadow casters do not have a mesh that accurately represents their shape. Examples include a billboard, a particle system, or a mesh textured with an alpha matte (e.g. a tree leaf). These create shadows based on their actual meshes, which do not match the actual appearance of the objects. For example, a cloud of smoke on a billboard casts a rectangular shadow.
(Image-6) Shadows in OpenGL in the SoftwareOK-3D project |
FAQ 31: Updated on: 4 September 2024 10:55