MCPcopy Create free account
hub / github.com/TheRealMJP/SHforHLSL / Init

Method Init

SHTest/SampleFramework12/v1.04/Graphics/Skybox.cpp:48–215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46}
47
48bool SkyCache::Init(const Float3& sunDirection_, float sunSize, const Float3& groundAlbedo_, float turbidity, bool createCubemap)
49{
50 Float3 sunDirection = sunDirection_;
51 Float3 groundAlbedo = groundAlbedo_;
52 sunDirection.y = Saturate(sunDirection.y);
53 sunDirection = Float3::Normalize(sunDirection);
54 turbidity = Clamp(turbidity, 1.0f, 32.0f);
55 groundAlbedo = Saturate(groundAlbedo);
56 sunSize = Max(sunSize, 0.01f);
57
58 // Do nothing if we're already up-to-date
59 if(Initialized() && sunDirection == SunDirection && groundAlbedo == Albedo && turbidity == Turbidity && SunSize == sunSize)
60 return false;
61
62 Shutdown();
63
64 sunDirection.y = Saturate(sunDirection.y);
65 sunDirection = Float3::Normalize(sunDirection);
66 turbidity = Clamp(turbidity, 1.0f, 32.0f);
67 groundAlbedo = Saturate(groundAlbedo);
68
69 float thetaS = AngleBetween(sunDirection, Float3(0, 1, 0));
70 float elevation = Pi_2 - thetaS;
71 StateR = arhosek_rgb_skymodelstate_alloc_init(turbidity, groundAlbedo.x, elevation);
72 StateG = arhosek_rgb_skymodelstate_alloc_init(turbidity, groundAlbedo.y, elevation);
73 StateB = arhosek_rgb_skymodelstate_alloc_init(turbidity, groundAlbedo.z, elevation);
74
75 Albedo = groundAlbedo;
76 Elevation = elevation;
77 SunDirection = sunDirection;
78 Turbidity = turbidity;
79 SunSize = sunSize;
80
81 // Compute the irradiance of the sun for a surface perpendicular to the sun using monte carlo integration.
82 // Note that the solar radiance function provided by the authors of this sky model only works using
83 // spectral rendering, so we sample a range of wavelengths and then convert to RGB.
84 SampledSpectrum groundAlbedoSpectrum = SampledSpectrum::FromRGB(Albedo, SpectrumType::Reflectance);
85 SampledSpectrum solarRadiance;
86
87 // Init the Hosek solar radiance model for all wavelengths
88 ArHosekSkyModelState* skyStates[NumSpectralSamples] = { };
89 for(int32 i = 0; i < NumSpectralSamples; ++i)
90 skyStates[i] = arhosekskymodelstate_alloc_init(thetaS, turbidity, groundAlbedoSpectrum[i]);
91
92 SunIrradiance = Float3(0.0f);
93
94 // Uniformly sample the solid area of the solar disc.
95 // Note that we use the *actual* sun size here and not the passed in the sun direction, so that
96 // we always end up with the appropriate intensity. This allows changing the size of the sun
97 // as it appears in the skydome without actually changing the sun intensity.
98 Float3 sunDirX = Float3::Perpendicular(sunDirection);
99 Float3 sunDirY = Float3::Cross(sunDirection, sunDirX);
100 Float3x3 sunOrientation = Float3x3(sunDirX, sunDirY, sunDirection);
101
102 const uint64 NumSamples = 8;
103 for(uint64 x = 0; x < NumSamples; ++x)
104 {
105 for(uint64 y = 0; y < NumSamples; ++y)

Callers 15

GenerateUniformSGsFunction · 0.45
CompileShaderFunction · 0.45
InitializeFunction · 0.45
InitializeMethod · 0.45
GetTextureDataFunction · 0.45
InitFromAssimpMeshMethod · 0.45
InitBoxMethod · 0.45
InitPlaneMethod · 0.45
CreateWithAssimpMethod · 0.45
GenerateBoxSceneMethod · 0.45
GenerateBoxTestSceneMethod · 0.45
GeneratePlaneSceneMethod · 0.45

Calls 15

SaturateFunction · 0.85
ClampFunction · 0.85
MaxFunction · 0.85
AngleBetweenFunction · 0.85
Float3Class · 0.85
Float3x3Class · 0.85
SampleDirectionConeFunction · 0.85
SampleDirectionCone_PDFFunction · 0.85

Tested by

no test coverage detected