Software-OK
≡... News | ... Home | ... FAQ | Impressum | Contact | Listed at | Thank you |

  
HOME ► Faq ► FAQ - Windows-CPP-und-C ► ««« »»»

3D C++ C shadows in OpenGL and DirectX!


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!
2.) ... Example 1 shadow with tested source code!
3.) ... The classic shadow example from standard OpenGL!
..... more to follow
X.) ... Why this page and other links and information about shadows and shading!



See also: ►  What are shades?

1.) The shadow and shading difference Shadow vs Shadow!

On the left in the picture is the shading! ( ... see picture 1 points 1 and 2 )

On the right in the picture is the shadow ( ... see picture 1 points 3 and 4 )

PS: In my opinion, shading is a much more important tool in 3D design than shadows, especially since there are actually no shadows in virtual worlds ;-) However, you can achieve pretty good results if you don't try to top reality!


(Image-1) Shadow vs Shading
Shadow vs Shading


-
▲ Back to the top ▲


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!



(Image-2) 3D C++ C shadows in OpenGL!
3D C++ C shadows in OpenGL!

-
▲ Back to the top ▲


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!
Classic shadow examples with OpenGL!

-
▲ Back to the top ▲




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
Shaders 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!
3D C++ C shadows in OpenGL and DirectX!

-
▲ Back to the top ▲


-
▲ Back to the top ▲



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
Shadows in OpenGL in the SoftwareOK-3D project

-
▲ Back to the top ▲




FAQ 31: Updated on: 4 September 2024 10:55 Windows
Windows-CPP-und-C

Difference between time(0) and clock() in CPP and C?


cpp, The main difference between time and clock in CPP and C is what is counted For time it is seconds from 1.1.1970 and for clock it is milliseconds since program
Windows-CPP-und-C

WHAT is MFC?


MFC stands for Microsoft Foundation Class Library MFC is intended as a C++ object-oriented library for developing desktop applications for MS Windows.
Windows-CPP-und-C

Differences between GetWindowsDirectory and GetSystemDirectory?


The difference between GetWindowsDirectory and GetSystemDirectory is quickly explained and understood The GetSystemDirectory  and  GetWindowsDirectory  are
Windows-CPP-und-C

Dark theme in Win32 applications with menu and title bar!


It is not that easy to activate and use Dark Theme in Win32 applications with menu and title bar for Windows 11 & 10 Here I have found two open source projects
Windows-CPP-und-C

What is Perlin Noise?


At some point while programming you are confronted with the term Perlin or Noise or Perlin-Noise and ask yourself what kind of function it is and what is
Windows-CPP-und-C

Visual Studio 2022 takes forever and is slow, why?


It is difficult to work with Visual Studio 2022 on old hardware, it takes a long time and is very slow, thats why you need the latest hardware Ideally
Windows-CPP-und-C

Use WebView2?


Is a new control and is a browser control in Microsoft called WebView2, successor to CHtmlView or IWebBrowser Contents: 1. The new Microsoft browser

»»

  My question is not there in the FAQ
Asked questions on this answer:
Keywords: cpp, windows, shadows, opengl, directx, most, complex, tasks, programming, often, confused, with, shading, during, development, although, Questions, Answers, Software




  

  + Freeware
  + Order on the PC
  + File management
  + Automation
  + Office Tools
  + PC testing tools
  + Decoration and fun
  + Desktop-Clocks
  + Security

  + SoftwareOK Pages
  + Micro Staff
  + Freeware-1
  + Freeware-2
  + Freeware-3
  + FAQ
  + Downloads

  + Top
  + Desktop-OK
  + The Quad Explorer
  + Don't Sleep
  + Win-Scan-2-PDF
  + Quick-Text-Past
  + Print Folder Tree
  + Find Same Images
  + Experience-Index-OK
  + Font-View-OK


  + Freeware
  + WinBin2Iso
  + ThisIsMyFile
  + TheAeroClock
  + Bitte.Wenden
  + CoronaKO
  + MatriX.CoronaKO
  + Find.Same.Images.OK
  + 3D.Benchmark.OK
  + PhotoResizerOK
  + PAD-s


Home | Thanks | Contact | Link me | FAQ | Settings | Windows 10 | English-AV | Impressum | Translate | PayPal | PAD-s

 © 2025 by Nenad Hrg softwareok.de • softwareok.com • softwareok.com • softwareok.eu


► How to allow/disallow Remote Assistance connections to Windows-7 PC? ◄
► WINDOWS SETTING MS SETTINGS PRIVACY TASKS ◄
► Start the Windows 7 cmd.exe in administrator mode? ◄
► How to allow/disallow Remote Assistance connections to Windows-7 PC? ◄


This website does not store personal data. However, third-party providers are used to display ads,
which are managed by Google and comply with the IAB Transparency and Consent Framework (IAB-TCF).
The CMP ID is 300 and can be individually customized at the bottom of the page.
more Infos & Privacy Policy

....