Skip to content

Commit 1ad2f17

Browse files
EnvMapRenderer: added Scale parameter
1 parent fb53178 commit 1ad2f17

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

Components/interface/EnvMapRenderer.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ class EnvMapRenderer
130130

131131
/// Option flags.
132132
OPTION_FLAGS Options = OPTION_FLAG_NONE;
133+
134+
/// Scaling factor to apply to the environment map.
135+
float3 Scale = {1, 1, 1};
133136
};
134137

135138
/// Prepares the environment map renderer for rendering.

Components/src/EnvMapRenderer.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ struct EnvMapRenderer::EnvMapShaderAttribs
5252
float MipLevel = 0.f;
5353
float Alpha = 0.f;
5454
float Padding = 0.f;
55+
56+
float4 Scale;
5557
};
5658

5759
EnvMapRenderer::EnvMapRenderer(const CreateInfo& CI) :
@@ -233,6 +235,7 @@ void EnvMapRenderer::Prepare(IDeviceContext* pContext,
233235
m_ShaderAttribs->AverageLogLum = Attribs.AverageLogLum;
234236
m_ShaderAttribs->MipLevel = Attribs.MipLevel;
235237
m_ShaderAttribs->Alpha = Attribs.Alpha;
238+
m_ShaderAttribs->Scale = float4{Attribs.Scale, 1};
236239

237240
pContext->UpdateBuffer(m_RenderAttribsCB, 0, sizeof(EnvMapShaderAttribs), m_ShaderAttribs.get(), RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
238241
StateTransitionDesc Barrier{m_RenderAttribsCB, RESOURCE_STATE_UNKNOWN, RESOURCE_STATE_CONSTANT_BUFFER, STATE_TRANSITION_FLAG_UPDATE_STATE};

Shaders/Common/private/EnvMap.psh

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ cbuffer cbEnvMapRenderAttribs
1212
{
1313
ToneMappingAttribs g_ToneMappingAttribs;
1414

15-
float AverageLogLum;
16-
float MipLevel;
17-
float Alpha;
15+
float g_AverageLogLum;
16+
float g_MipLevel;
17+
float g_Alpha;
1818
float Unusued2;
19+
20+
float4 g_Scale;
1921
}
2022

2123
#if ENV_MAP_TYPE == ENV_MAP_TYPE_CUBE
@@ -25,12 +27,12 @@ Texture2D EnvMap;
2527
#endif
2628
SamplerState EnvMap_sampler;
2729

28-
float3 SampleEnvrionmentMap(float3 R, float MipLevel)
30+
float3 SampleEnvrionmentMap(float3 R, float g_MipLevel)
2931
{
3032
#if ENV_MAP_TYPE == ENV_MAP_TYPE_CUBE
31-
return EnvMap.SampleLevel(EnvMap_sampler, R, MipLevel).rgb;
33+
return EnvMap.SampleLevel(EnvMap_sampler, R, g_MipLevel).rgb;
3234
#elif ENV_MAP_TYPE == ENV_MAP_TYPE_SPHERE
33-
return EnvMap.SampleLevel(EnvMap_sampler, TransformDirectionToSphereMapUV(R), MipLevel).rgb;
35+
return EnvMap.SampleLevel(EnvMap_sampler, TransformDirectionToSphereMapUV(R), g_MipLevel).rgb;
3436
#endif
3537
}
3638

@@ -44,10 +46,10 @@ SampleEnvMapOutput SampleEnvMap(in float4 ClipPos)
4446
{
4547
float4 WorldPos = mul(ClipPos, g_Camera.mViewProjInv);
4648
float3 Direction = WorldPos.xyz / WorldPos.w - g_Camera.f4Position.xyz;
47-
float3 Color = SampleEnvrionmentMap(normalize(Direction), MipLevel);
49+
float3 Color = SampleEnvrionmentMap(normalize(Direction), g_MipLevel) * g_Scale.rgb;
4850

4951
#if TONE_MAPPING_MODE > TONE_MAPPING_MODE_NONE
50-
Color.rgb = ToneMap(Color.rgb, g_ToneMappingAttribs, AverageLogLum);
52+
Color.rgb = ToneMap(Color.rgb, g_ToneMappingAttribs, g_AverageLogLum);
5153
#endif
5254

5355
#if CONVERT_OUTPUT_TO_SRGB
@@ -63,7 +65,7 @@ SampleEnvMapOutput SampleEnvMap(in float4 ClipPos)
6365
#endif
6466

6567
SampleEnvMapOutput Output;
66-
Output.Color = float4(Color.rgb, Alpha);
68+
Output.Color = float4(Color.rgb, g_Alpha);
6769
Output.MotionVector = MotionVector;
6870
return Output;
6971
}

0 commit comments

Comments
 (0)