File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed
Runtime/Randomization/Randomizers/RandomizerExamples/Randomizers
Tests/Runtime/Randomization/ScenarioTests Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change 11using System ;
2+ using UnityEngine ;
23using UnityEngine . Perception . GroundTruth ;
34using UnityEngine . Perception . Randomization . Scenarios ;
45
56namespace RandomizationTests . ScenarioTests
67{
8+ [ AddComponentMenu ( "" ) ]
79 class TestFixedLengthScenario : FixedLengthScenario
810 {
911 protected override void OnComplete ( )
You can’t perform that action at this time.
0 commit comments