LCOV - code coverage report
Current view: top level - source/graphics - LightEnv.cpp (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 18 40 45.0 %
Date: 2026-12-03 01:19:39 Functions: 2 5 40.0 %

          Line data    Source code
       1             : /* Copyright (C) 2025 Wildfire Games.
       2             :  * This file is part of 0 A.D.
       3             :  *
       4             :  * 0 A.D. is free software: you can redistribute it and/or modify
       5             :  * it under the terms of the GNU General Public License as published by
       6             :  * the Free Software Foundation, either version 2 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * 0 A.D. is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  * GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License
      15             :  * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : #include "precompiled.h"
      19             : 
      20             : #include "LightEnv.h"
      21             : 
      22             : #include "maths/MathUtil.h"
      23             : #include "ps/CStrInternStatic.h"
      24             : #include "renderer/backend/IDeviceCommandContext.h"
      25             : #include "renderer/backend/IShaderProgram.h"
      26             : #include "renderer/RenderingOptions.h"
      27             : 
      28             : #include <cmath>
      29             : 
      30           4 : CLightEnv::CLightEnv()
      31           4 :     : m_Elevation(DEGTORAD(45)),
      32           4 :     m_Rotation(DEGTORAD(315)),
      33           4 :     m_SunColor(1.5, 1.5, 1.5),
      34           4 :     m_AmbientColor(0x50/255.f, 0x60/255.f, 0x85/255.f),
      35           4 :     m_FogColor(0xCC/255.f, 0xCC/255.f, 0xE5/255.f),
      36           4 :     m_FogFactor(0.000f),
      37           4 :     m_FogMax(0.5f),
      38           4 :     m_Brightness(0.0f), m_Contrast(1.0f), m_Saturation(0.99f), m_Bloom(0.1999f)
      39             : {
      40           4 :     CalculateSunDirection();
      41           4 : }
      42             : 
      43           0 : void CLightEnv::SetElevation(float f)
      44             : {
      45           0 :     m_Elevation = f;
      46           0 :     CalculateSunDirection();
      47           0 : }
      48             : 
      49           0 : void CLightEnv::SetRotation(float f)
      50             : {
      51           0 :     m_Rotation = f;
      52           0 :     CalculateSunDirection();
      53           0 : }
      54             : 
      55           7 : void CLightEnv::CalculateSunDirection()
      56             : {
      57           7 :     m_SunDir.Y = -sinf(m_Elevation);
      58           7 :     float scale = 1 + m_SunDir.Y;
      59           7 :     m_SunDir.X = scale * sinf(m_Rotation);
      60           7 :     m_SunDir.Z = scale * cosf(m_Rotation);
      61           7 :     m_SunDir.Normalize();
      62           7 : }
      63             : 
      64           0 : void CLightEnv::Bind(
      65             :     Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
      66             :     Renderer::Backend::IShaderProgram* shaderProgram) const
      67             : {
      68           0 :     deviceCommandContext->SetUniform(
      69           0 :         shaderProgram->GetBindingSlot(str_ambient), m_AmbientColor.AsFloatArray());
      70           0 :     deviceCommandContext->SetUniform(
      71           0 :         shaderProgram->GetBindingSlot(str_sunDir), GetSunDir().AsFloatArray());
      72           0 :     deviceCommandContext->SetUniform(
      73           0 :         shaderProgram->GetBindingSlot(str_sunColor), m_SunColor.AsFloatArray());
      74             : 
      75           0 :     deviceCommandContext->SetUniform(
      76           0 :         shaderProgram->GetBindingSlot(str_fogColor),
      77           0 :         m_FogColor.AsFloatArray());
      78           0 :     deviceCommandContext->SetUniform(
      79           0 :         shaderProgram->GetBindingSlot(str_fogParams),
      80           0 :         m_FogFactor, g_RenderingOptions.GetFog() ? m_FogMax : 1.0f);
      81           0 : }

Generated by: LCOV version 1.16