Skip to content

Commit 4354548

Browse files
committed
TextureRandomizer now works for tutorial's HueShift shader in HDRP
1 parent f5189e1 commit 4354548

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

com.unity.perception/Runtime/Randomization/Randomizers/RandomizerExamples/Randomizers/TextureRandomizer.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ namespace UnityEngine.Perception.Randomization.Randomizers.SampleRandomizers
1111
[AddRandomizerMenu("Perception/Texture Randomizer")]
1212
public class TextureRandomizer : Randomizer
1313
{
14+
static readonly int k_BaseMap = Shader.PropertyToID("_BaseMap");
1415
#if HDRP_PRESENT
15-
static readonly int k_BaseTexture = Shader.PropertyToID("_BaseColorMap");
16-
#else
17-
static readonly int k_BaseTexture = Shader.PropertyToID("_BaseMap");
16+
const string k_TutorialHueShaderName = "Shader Graphs/HueShiftOpaque";
17+
static readonly int k_BaseColorMap = Shader.PropertyToID("_BaseColorMap");
1818
#endif
1919

2020
/// <summary>
@@ -30,8 +30,16 @@ protected override void OnIterationStart()
3030
var tags = tagManager.Query<TextureRandomizerTag>();
3131
foreach (var tag in tags)
3232
{
33-
var renderer = tag.GetComponent<MeshRenderer>();
34-
renderer.material.SetTexture(k_BaseTexture, texture.Sample());
33+
var renderer = tag.GetComponent<Renderer>();
34+
#if HDRP_PRESENT
35+
// Choose the appropriate shader texture property ID depending on whether the current material is
36+
// using the default HDRP/lit shader or the Perception tutorial's HueShiftOpaque shader
37+
var material = renderer.material;
38+
var propertyId = material.shader.name == k_TutorialHueShaderName ? k_BaseMap : k_BaseColorMap;
39+
material.SetTexture(propertyId, texture.Sample());
40+
#else
41+
renderer.material.SetTexture(k_BaseMap, texture.Sample());
42+
#endif
3543
}
3644
}
3745
}

com.unity.perception/Tests/Runtime/Randomization/ScenarioTests/TestFixedLengthScenario.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System;
2+
using UnityEngine;
23
using UnityEngine.Perception.GroundTruth;
34
using UnityEngine.Perception.Randomization.Scenarios;
45

56
namespace RandomizationTests.ScenarioTests
67
{
8+
[AddComponentMenu("")]
79
class TestFixedLengthScenario : FixedLengthScenario
810
{
911
protected override void OnComplete()

0 commit comments

Comments
 (0)