| 47 | } |
| 48 | |
| 49 | void MaterialComplexityMaterialShader::WrapperShader::Bind(BindParameters& params) |
| 50 | { |
| 51 | auto& drawCall = *params.DrawCall; |
| 52 | |
| 53 | // Get original material from the draw call |
| 54 | IMaterial* material = nullptr; |
| 55 | switch (Domain) |
| 56 | { |
| 57 | case MaterialDomain::Surface: |
| 58 | case MaterialDomain::Terrain: |
| 59 | material = *(IMaterial**)&drawCall.Surface.Lightmap; |
| 60 | break; |
| 61 | case MaterialDomain::Particle: |
| 62 | material = *(IMaterial**)&drawCall.ObjectPosition; |
| 63 | break; |
| 64 | case MaterialDomain::Decal: |
| 65 | material = drawCall.Material; |
| 66 | break; |
| 67 | } |
| 68 | |
| 69 | // Disable lightmaps |
| 70 | const auto lightmapsEnable = EnableLightmapsUsage; |
| 71 | EnableLightmapsUsage = false; |
| 72 | |
| 73 | // Estimate the shader complexity |
| 74 | ASSERT_LOW_LAYER(material && material->IsReady()); |
| 75 | material->Bind(params); |
| 76 | GPUPipelineState* materialPs = params.GPUContext->GetState(); |
| 77 | const float complexity = (float)Math::Min(materialPs->Complexity, MATERIAL_COMPLEXITY_LIMIT) / MATERIAL_COMPLEXITY_LIMIT; |
| 78 | |
| 79 | // Draw with custom color |
| 80 | const Color color(complexity, complexity, complexity, 1.0f); |
| 81 | MaterialAsset->SetParameterValue(TEXT("Color"), Variant(color)); |
| 82 | MaterialAsset->Bind(params); |
| 83 | |
| 84 | EnableLightmapsUsage = lightmapsEnable; |
| 85 | } |
| 86 | |
| 87 | MaterialComplexityMaterialShader::MaterialComplexityMaterialShader() |
| 88 | { |