Skip to content

Commit ff6ce78

Browse files
committed
fix missing texture reduction scale uniform
fix #129
1 parent e586185 commit ff6ce78

3 files changed

Lines changed: 36 additions & 6 deletions

File tree

‎src/Scene/Pkg/Parse/Uniform/UniformSource.cpp‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,11 @@ auto ShadowUniformSource::Evaluate(ref<dyn<UniformUpdateContext>>,
964964

965965
auto TextureUniformSource::Describe(mut_ref<dyn<UniformBindingSink>> sink) const
966966
-> Result<empty, UniformError> {
967+
auto reduction = Bind(sink,
968+
TextureUniformOutput::ReductionScale,
969+
"g_TextureReductionScale"_str,
970+
UniformValueShape::Float(u32(1)));
971+
if (reduction.is_err()) return reduction;
967972
for (usize index {}; index < WE_GLTEX_NAMES.len(); ++index) {
968973
auto resolution = Bind(sink,
969974
TextureResolutionOutput(index.to_primitive()),
@@ -1002,7 +1007,9 @@ auto TextureUniformSource::Evaluate(ref<dyn<UniformUpdateContext>> context,
10021007
mut_ref<dyn<UniformValueSink>> sink) const
10031008
-> Result<empty, UniformError> {
10041009
UniformWriter writer(sink);
1005-
auto resources = context->Resources();
1010+
// Authored pixel offsets use unreduced texture coordinates; no global reduction is applied.
1011+
writer.Write(TextureUniformOutput::ReductionScale, 1.0f);
1012+
auto resources = context->Resources();
10061013
for (usize index {}; index < WE_GLTEX_NAMES.len(); ++index) {
10071014
auto texture = resources->Texture(index);
10081015
if (texture.is_none()) continue;

‎src/Scene/Pkg/Parse/Uniform/UniformSource.cppm‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,12 @@ enum class AudioUniformOutput : rstd::uint32_t
8383

8484
enum class TextureUniformOutput : rstd::uint32_t
8585
{
86-
Resolution0 = 0,
87-
Mipmap0 = 16,
88-
Rotation0 = 32,
89-
Translation0 = 48,
90-
Texel0 = 64,
86+
Resolution0 = 0,
87+
Mipmap0 = 16,
88+
Rotation0 = 32,
89+
Translation0 = 48,
90+
Texel0 = 64,
91+
ReductionScale = 80,
9192
};
9293

9394
enum class ParticleTrailUniformOutput : rstd::uint32_t

‎tests/tests/scene-runtime/scene_runtime_tests.cpp‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,21 @@ class ShapeSink {
8585
} else if (name == "g_LightsPosition"_str) {
8686
light_position_shape = shape;
8787
found_light_position = true;
88+
} else if (name == "g_TextureReductionScale"_str) {
89+
texture_reduction_shape = shape;
90+
found_texture_reduction = true;
8891
}
8992
return rstd::Ok(true);
9093
}
9194

9295
owe::UniformValueShape model_shape;
9396
owe::UniformValueShape spectrum_shape;
9497
owe::UniformValueShape light_position_shape;
98+
owe::UniformValueShape texture_reduction_shape;
9599
bool found_model { false };
96100
bool found_spectrum { false };
97101
bool found_light_position { false };
102+
bool found_texture_reduction { false };
98103
};
99104

100105
class UpdateContext {
@@ -434,6 +439,23 @@ TEST(ShadowUniformSource, UsesAuthoredCascadeExtentAndLightObjectFrame) {
434439
EXPECT_FLOAT_EQ(atlas[usize(8)], 2.0f / 3.0f);
435440
}
436441

442+
TEST(TextureUniformSource, PublishesUnreducedTextureScale) {
443+
owe::TextureUniformSource source;
444+
scene_test::ShapeSink binding_sink;
445+
auto bindings = rstd::dyn<owe::UniformBindingSink>::from_ref(binding_sink);
446+
ASSERT_TRUE(source.Describe(bindings.as_mut_ref()).is_ok());
447+
ASSERT_TRUE(binding_sink.found_texture_reduction);
448+
EXPECT_EQ(binding_sink.texture_reduction_shape.scalar, owe::UniformScalarType::Float32);
449+
EXPECT_EQ(binding_sink.texture_reduction_shape.kind, owe::UniformValueKind::Linear);
450+
EXPECT_EQ(binding_sink.texture_reduction_shape.min_elements, u32(1));
451+
EXPECT_EQ(binding_sink.texture_reduction_shape.max_elements, u32(1));
452+
453+
owe::SceneFrame frame;
454+
auto scale = scene_test::Capture(frame, source, owe::TextureUniformOutput::ReductionScale);
455+
ASSERT_EQ(scale.size(), usize(1));
456+
EXPECT_FLOAT_EQ(scale[usize()], 1.0f);
457+
}
458+
437459
TEST(TextureUniformSource, StaticTextureUsesIdentityTransform) {
438460
owe::SceneFrame frame;
439461
scene_test::StaticTextureResources resources;

0 commit comments

Comments
 (0)