| 44 | } |
| 45 | |
| 46 | void ParticleMaterialShader::Bind(BindParameters& params) |
| 47 | { |
| 48 | // Prepare |
| 49 | auto context = params.GPUContext; |
| 50 | auto& view = params.RenderContext.View; |
| 51 | auto& drawCall = *params.DrawCall; |
| 52 | Span<byte> cb(_cbData.Get(), _cbData.Count()); |
| 53 | ASSERT_LOW_LAYER(cb.Length() >= sizeof(ParticleMaterialShaderData)); |
| 54 | auto materialData = reinterpret_cast<ParticleMaterialShaderData*>(cb.Get()); |
| 55 | cb = cb.Slice(sizeof(ParticleMaterialShaderData)); |
| 56 | int32 srv = 2; |
| 57 | |
| 58 | // Setup features |
| 59 | if (EnumHasAnyFlags(_info.FeaturesFlags, MaterialFeaturesFlags::GlobalIllumination)) |
| 60 | GlobalIlluminationFeature::Bind(params, cb, srv); |
| 61 | ForwardShadingFeature::Bind(params, cb, srv); |
| 62 | |
| 63 | // Setup parameters |
| 64 | MaterialParameter::BindMeta bindMeta; |
| 65 | bindMeta.Context = context; |
| 66 | bindMeta.Constants = cb; |
| 67 | bindMeta.Input = nullptr; |
| 68 | bindMeta.Buffers = params.RenderContext.Buffers; |
| 69 | bindMeta.CanSampleDepth = GPUDevice::Instance->Limits.HasReadOnlyDepth; |
| 70 | bindMeta.CanSampleGBuffer = true; |
| 71 | MaterialParams::Bind(params.ParamsLink, bindMeta); |
| 72 | |
| 73 | // Setup particles data |
| 74 | context->BindSR(0, drawCall.Particle.Particles->GPU.Buffer->View()); |
| 75 | context->BindSR(1, drawCall.Particle.Particles->GPU.SortedIndices ? drawCall.Particle.Particles->GPU.SortedIndices->View() : nullptr); |
| 76 | |
| 77 | // Setup particles attributes binding info |
| 78 | { |
| 79 | const auto& p = *params.ParamsLink->This; |
| 80 | for (int32 i = 0; i < p.Count(); i++) |
| 81 | { |
| 82 | const auto& param = p.At(i); |
| 83 | if (param.GetParameterType() == MaterialParameterType::Integer && param.GetName().StartsWith(TEXT("Particle."))) |
| 84 | { |
| 85 | const StringView name(param.GetName().Get() + 9, param.GetName().Length() - 9); |
| 86 | const int32 offset = drawCall.Particle.Particles->Layout->FindAttributeOffset(name); |
| 87 | ASSERT_LOW_LAYER(bindMeta.Constants.Get() && bindMeta.Constants.Length() >= (int32)(param.GetBindOffset() + sizeof(int32))); |
| 88 | *((int32*)(bindMeta.Constants.Get() + param.GetBindOffset())) = offset; |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | // Setup material constants |
| 94 | { |
| 95 | static StringView ParticlePosition(TEXT("Position")); |
| 96 | static StringView ParticleSpriteSize(TEXT("SpriteSize")); |
| 97 | static StringView ParticleSpriteFacingMode(TEXT("SpriteFacingMode")); |
| 98 | static StringView ParticleSpriteFacingVector(TEXT("SpriteFacingVector")); |
| 99 | static StringView ParticleVelocityOffset(TEXT("Velocity")); |
| 100 | static StringView ParticleRotationOffset(TEXT("Rotation")); |
| 101 | static StringView ParticleScaleOffset(TEXT("Scale")); |
| 102 | static StringView ParticleModelFacingModeOffset(TEXT("ModelFacingMode")); |
| 103 |
nothing calls this directly
no test coverage detected