MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / Bind

Method Bind

Source/Engine/Graphics/Materials/MaterialShaderFeatures.cpp:19–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17#include "Engine/Renderer/ReflectionsPass.h"
18
19void ForwardShadingFeature::Bind(MaterialShader::BindParameters& params, Span<byte>& cb, int32& srv)
20{
21 auto cache = params.RenderContext.List;
22 auto& view = params.RenderContext.View;
23 auto& drawCall = *params.DrawCall;
24 auto& data = *(Data*)cb.Get();
25 ASSERT_LOW_LAYER(cb.Length() >= sizeof(Data));
26 const int32 envProbeShaderRegisterIndex = srv + 0;
27 const int32 skyLightShaderRegisterIndex = srv + 1;
28 const int32 shadowsBufferRegisterIndex = srv + 2;
29 const int32 shadowMapShaderRegisterIndex = srv + 3;
30 const int32 volumetricFogTextureRegisterIndex = srv + 4;
31 const int32 preIntegratedGFRegisterIndex = srv + 5;
32 const bool canUseShadow = view.Pass != DrawPass::Depth;
33
34 // Set fog input
35 data.ExponentialHeightFog = cache->Fog.ExponentialHeightFogData;
36 data.VolumetricFogData = cache->Fog.VolumetricFogData;
37 params.GPUContext->BindSR(volumetricFogTextureRegisterIndex, cache->Fog.VolumetricFogTexture);
38
39 // Set directional light input
40 if (cache->DirectionalLights.HasItems())
41 {
42 const auto& dirLight = cache->DirectionalLights.First();
43 GPUTexture* shadowMapAtlas;
44 GPUBufferView* shadowsBuffer;
45 ShadowsPass::GetShadowAtlas(params.RenderContext.Buffers, shadowMapAtlas, shadowsBuffer);
46 const bool useShadow = shadowMapAtlas && canUseShadow && dirLight.HasShadow;
47 dirLight.SetShaderData(data.DirectionalLight, useShadow);
48 params.GPUContext->BindSR(shadowsBufferRegisterIndex, shadowsBuffer);
49 params.GPUContext->BindSR(shadowMapShaderRegisterIndex, shadowMapAtlas);
50 }
51 else
52 {
53 Platform::MemoryClear(&data.DirectionalLight, sizeof(data.DirectionalLight));
54 params.GPUContext->UnBindSR(shadowsBufferRegisterIndex);
55 params.GPUContext->UnBindSR(shadowMapShaderRegisterIndex);
56 }
57
58 // Set sky light
59 if (cache->SkyLights.HasItems())
60 {
61 auto& skyLight = cache->SkyLights.First();
62 skyLight.SetShaderData(data.SkyLight, false);
63 const auto texture = skyLight.Image ? skyLight.Image->GetTexture() : nullptr;
64 params.GPUContext->BindSR(skyLightShaderRegisterIndex, GET_TEXTURE_VIEW_SAFE(texture));
65 }
66 else
67 {
68 Platform::MemoryClear(&data.SkyLight, sizeof(data.SkyLight));
69 params.GPUContext->UnBindSR(skyLightShaderRegisterIndex);
70 }
71
72 // Set reflection probe data
73 bool noEnvProbe = true;
74 // TODO: optimize env probe searching for a transparent material - use spatial cache for renderer to find it
75 const BoundingSphere objectBounds(drawCall.ObjectPosition, drawCall.ObjectRadius);
76 float minDistanceSq = MAX_float;

Callers

nothing calls this directly

Calls 15

MemoryClearFunction · 0.85
EnumHasAnyFlagsFunction · 0.85
SetShaderDataMethod · 0.80
GetTextureMethod · 0.80
SliceMethod · 0.80
BoundingSphereClass · 0.50
InstanceClass · 0.50
GetMethod · 0.45
LengthMethod · 0.45
BindSRMethod · 0.45
HasItemsMethod · 0.45
FirstMethod · 0.45

Tested by

no test coverage detected