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

Method Bind

Source/Engine/Graphics/Materials/DeformableMaterialShader.cpp:35–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33}
34
35void DeformableMaterialShader::Bind(BindParameters& params)
36{
37 // Prepare
38 auto context = params.GPUContext;
39 auto& view = params.RenderContext.View;
40 auto& drawCall = *params.DrawCall;
41 Span<byte> cb(_cbData.Get(), _cbData.Count());
42 ASSERT_LOW_LAYER(cb.Length() >= sizeof(DeformableMaterialShaderData));
43 auto materialData = reinterpret_cast<DeformableMaterialShaderData*>(cb.Get());
44 cb = cb.Slice(sizeof(DeformableMaterialShaderData));
45 int32 srv = 1;
46
47 // Setup features
48 if (_info.BlendMode != MaterialBlendMode::Opaque)
49 ForwardShadingFeature::Bind(params, cb, srv);
50
51 // Setup parameters
52 MaterialParameter::BindMeta bindMeta;
53 bindMeta.Context = context;
54 bindMeta.Constants = cb;
55 bindMeta.Input = nullptr;
56 bindMeta.Buffers = params.RenderContext.Buffers;
57 bindMeta.CanSampleDepth = false;
58 bindMeta.CanSampleGBuffer = false;
59 MaterialParams::Bind(params.ParamsLink, bindMeta);
60
61 // Setup material constants
62 {
63 Matrix::Transpose(drawCall.World, materialData->WorldMatrix);
64 Matrix::Transpose(drawCall.Deformable.LocalMatrix, materialData->LocalMatrix);
65 materialData->WorldDeterminantSign = drawCall.WorldDeterminant ? -1.0f : 1.0f;
66 materialData->Segment = drawCall.Deformable.Segment;
67 materialData->ChunksPerSegment = drawCall.Deformable.ChunksPerSegment;
68 materialData->MeshMinZ = drawCall.Deformable.MeshMinZ;
69 materialData->MeshMaxZ = drawCall.Deformable.MeshMaxZ;
70 materialData->PerInstanceRandom = drawCall.PerInstanceRandom;
71 materialData->GeometrySize = drawCall.Deformable.GeometrySize;
72 }
73
74 // Bind spline deformation buffer
75 context->BindSR(0, drawCall.Deformable.SplineDeformation->View());
76
77 // Bind constants
78 if (_cb)
79 {
80 context->UpdateCB(_cb, _cbData.Get());
81 context->BindCB(0, _cb);
82 }
83
84 // Select pipeline state based on current pass and render mode
85 const bool wireframe = (_info.FeaturesFlags & MaterialFeaturesFlags::Wireframe) != MaterialFeaturesFlags::None || view.Mode == ViewMode::Wireframe;
86 CullMode cullMode = view.Pass == DrawPass::Depth ? CullMode::TwoSided : _info.CullMode;
87 if (cullMode != CullMode::TwoSided && drawCall.WorldDeterminant)
88 {
89 // Invert culling when scale is negative
90 cullMode = cullMode == CullMode::Normal ? CullMode::Inverted : CullMode::Normal;
91 }
92 PipelineStateCache* psCache = _cache.GetPS(view.Pass);

Callers

nothing calls this directly

Calls 13

BindFunction · 0.85
SliceMethod · 0.80
TransposeFunction · 0.50
GetMethod · 0.45
CountMethod · 0.45
LengthMethod · 0.45
BindSRMethod · 0.45
ViewMethod · 0.45
UpdateCBMethod · 0.45
BindCBMethod · 0.45
GetPSMethod · 0.45
SetStateMethod · 0.45

Tested by

no test coverage detected