MCPcopy Create free account
hub / github.com/carbonengine/trinity / UpdatePerObjectData

Method UpdatePerObjectData

trinity/Tr2VolumetricsRenderer.cpp:811–1045  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

809}
810
811void Tr2VolumetricsRenderer::UpdatePerObjectData( FogPerObjectData* data, const Matrix& view, const Matrix& projection, const Matrix& viewLast, const Matrix& projectionLast, const Vector3d& origin, const Vector3d& originShift, const Vector3& sunDirection, const Color& sunColor, uint32_t width, uint32_t height, uint32_t depth, const Vector3& jitter, const Tr2ShadowMap* cascadedShadowMap )
812{
813 float maxDistance = m_gameBackClip;
814 float maxDistanceVisibility = exp( -m_froxelFogSettings.thickness.value );
815 float baseDensity = m_froxelFogSettings.thickness.value / maxDistance;
816
817 float environmentIntensity = m_froxelFogSettings.environmentIntensity.value;
818
819 Color fogColor = m_froxelFogSettings.fogColor.value;
820 float backgroundVisibility = std::clamp( m_froxelFogSettings.backgroundVisibility.value, 0.0f, 1.0f );
821
822
823 //G is negative when light is scattered in the direction the light was already going in.
824 //Expose this value as positive, then negate and clamp it so that it's always negative.
825 //Exactly 0.0 and 1.0 both cause issues with the math in the shader, so clamp to a slightly smaller range.
826 float lightG = -std::clamp( m_froxelFogSettings.lightDirectionality.value, 0.001f, 0.999f );
827 float environmentG = -std::clamp( m_froxelFogSettings.environmentDirectionality.value, 0.001f, 0.999f );
828
829 Matrix inverseView = Inverse( view );
830 Matrix inverseProjection = Inverse( projection );
831
832 {
833
834 data->ResolutionX = width;
835 data->ResolutionY = height;
836 data->ResolutionZ = depth;
837
838 data->Jitter = jitter;
839 data->Far = maxDistance;
840
841 data->Scattering = Vector3( fogColor.r, fogColor.g, fogColor.b );
842 data->BaseDensity = baseDensity;
843
844 data->MaxDistanceVisibility = maxDistanceVisibility;
845 data->LightG = lightG;
846 data->EnvironmentIntensity = environmentIntensity;
847
848
849 //data->Extinction = extinction;
850
851
852 {
853 float exactFrequency = exp2f( -m_froxelFogSettings.fogNoiseFrequency.value );
854 float baseFrequency = exp2f( floor( -m_froxelFogSettings.fogNoiseFrequency.value ) );
855 float nextFrequency = baseFrequency * 2.0f;
856
857
858 double offsetX = origin.x * baseFrequency;
859 double offsetY = origin.y * baseFrequency;
860 double offsetZ = origin.z * baseFrequency;
861 offsetX -= floor( offsetX );
862 offsetY -= floor( offsetY );
863 offsetZ -= floor( offsetZ );
864
865 data->FogNoiseOffset = Vector3( (float)offsetX, (float)offsetY, (float)offsetZ );
866
867
868 data->FogNoiseFrequency = baseFrequency;

Callers

nothing calls this directly

Calls 13

CrossFunction · 0.85
Matrix4dFromMatrixFunction · 0.85
Matrix4dMultiplyFunction · 0.85
Matrix4dTransformFunction · 0.85
Vector4dClass · 0.85
Matrix4dCopyFunction · 0.85
TransposeFunction · 0.85
Matrix4dToMatrixFunction · 0.85
sizeMethod · 0.80
Vector3Class · 0.70
DotFunction · 0.50
Vector4Class · 0.50

Tested by

no test coverage detected