2
2
using UnityEngine ;
3
3
using UnityEngine . Rendering ;
4
4
5
+ using System . Linq ;
6
+
5
7
namespace UnityEditor
6
8
{
7
9
internal class LayeredLitGUI : LitGUI
@@ -66,22 +68,14 @@ internal struct SerializeableGUIDs
66
68
MaterialProperty layerCount = null ;
67
69
const string kLayerCount = "_LayerCount" ;
68
70
MaterialProperty [ ] layerTexWorldScale = new MaterialProperty [ kMaxLayerCount ] ;
69
- const string kLayerTexWorldScale = "_TexWorldScale" ;
70
71
MaterialProperty [ ] layerUVBase = new MaterialProperty [ kMaxLayerCount ] ;
71
- const string kLayerUVBase = "_UVBase" ;
72
72
MaterialProperty [ ] layerUVMappingMask = new MaterialProperty [ kMaxLayerCount ] ;
73
- const string kLayerUVMappingMask = "_UVMappingMask" ;
74
73
MaterialProperty [ ] layerUVDetail = new MaterialProperty [ kMaxLayerCount ] ;
75
- const string kLayerUVDetail = "_UVDetail" ;
76
74
MaterialProperty [ ] layerUVDetailsMappingMask = new MaterialProperty [ kMaxLayerCount ] ;
77
- const string kLayerUVDetailsMappingMask = "_UVDetailsMappingMask" ;
78
75
79
76
MaterialProperty layerEmissiveColor = null ;
80
- const string kLayerEmissiveColor = "_EmissiveColor" ;
81
77
MaterialProperty layerEmissiveColorMap = null ;
82
- const string kLayerEmissiveColorMap = "_EmissiveColorMap" ;
83
78
MaterialProperty layerEmissiveIntensity = null ;
84
- const string kLayerEmissiveIntensity = "_EmissiveIntensity" ;
85
79
86
80
private void FindLayerProperties ( MaterialProperty [ ] props )
87
81
{
@@ -90,16 +84,16 @@ private void FindLayerProperties(MaterialProperty[] props)
90
84
layerCount = FindProperty ( kLayerCount , props ) ;
91
85
for ( int i = 0 ; i < numLayer ; ++ i )
92
86
{
93
- layerTexWorldScale [ i ] = FindProperty ( string . Format ( "{0}{1}" , kLayerTexWorldScale , i ) , props ) ;
94
- layerUVBase [ i ] = FindProperty ( string . Format ( "{0}{1}" , kLayerUVBase , i ) , props ) ;
95
- layerUVMappingMask [ i ] = FindProperty ( string . Format ( "{0}{1}" , kLayerUVMappingMask , i ) , props ) ;
96
- layerUVDetail [ i ] = FindProperty ( string . Format ( "{0}{1}" , kLayerUVDetail , i ) , props ) ;
97
- layerUVDetailsMappingMask [ i ] = FindProperty ( string . Format ( "{0}{1}" , kLayerUVDetailsMappingMask , i ) , props ) ;
87
+ layerTexWorldScale [ i ] = FindProperty ( string . Format ( "{0}{1}" , kTexWorldScale , i ) , props ) ;
88
+ layerUVBase [ i ] = FindProperty ( string . Format ( "{0}{1}" , kUVBase , i ) , props ) ;
89
+ layerUVMappingMask [ i ] = FindProperty ( string . Format ( "{0}{1}" , kUVMappingMask , i ) , props ) ;
90
+ layerUVDetail [ i ] = FindProperty ( string . Format ( "{0}{1}" , kUVDetail , i ) , props ) ;
91
+ layerUVDetailsMappingMask [ i ] = FindProperty ( string . Format ( "{0}{1}" , kUVDetailsMappingMask , i ) , props ) ;
98
92
}
99
93
100
- layerEmissiveColor = FindProperty ( kLayerEmissiveColor , props ) ;
101
- layerEmissiveColorMap = FindProperty ( kLayerEmissiveColorMap , props ) ;
102
- layerEmissiveIntensity = FindProperty ( kLayerEmissiveIntensity , props ) ;
94
+ layerEmissiveColor = FindProperty ( kEmissiveColor , props ) ;
95
+ layerEmissiveColorMap = FindProperty ( kEmissiveColorMap , props ) ;
96
+ layerEmissiveIntensity = FindProperty ( kEmissiveIntensity , props ) ;
103
97
}
104
98
105
99
int numLayer
@@ -118,6 +112,8 @@ void SynchronizeAllLayersProperties()
118
112
119
113
void SynchronizeLayerProperties ( int layerIndex )
120
114
{
115
+ string [ ] exclusionList = { kTexWorldScale , kUVBase , kUVMappingMask , kUVDetail , kUVDetailsMappingMask } ;
116
+
121
117
Material material = m_MaterialEditor . target as Material ;
122
118
Material layerMaterial = m_MaterialLayers [ layerIndex ] ;
123
119
@@ -129,34 +125,38 @@ void SynchronizeLayerProperties(int layerIndex)
129
125
{
130
126
string propertyName = ShaderUtil . GetPropertyName ( layerShader , i ) ;
131
127
string layerPropertyName = propertyName + layerIndex ;
132
- if ( material . HasProperty ( layerPropertyName ) )
133
- {
134
- ShaderUtil . ShaderPropertyType type = ShaderUtil . GetPropertyType ( layerShader , i ) ;
135
- switch ( type )
136
- {
137
- case ShaderUtil . ShaderPropertyType . Color :
138
- {
139
- material . SetColor ( layerPropertyName , layerMaterial . GetColor ( propertyName ) ) ;
140
- break ;
141
- }
142
- case ShaderUtil . ShaderPropertyType . Float :
143
- case ShaderUtil . ShaderPropertyType . Range :
144
- {
145
- material . SetFloat ( layerPropertyName , layerMaterial . GetFloat ( propertyName ) ) ;
146
- break ;
147
- }
148
- case ShaderUtil . ShaderPropertyType . Vector :
149
- {
150
- material . SetVector ( layerPropertyName , layerMaterial . GetVector ( propertyName ) ) ;
151
- break ;
152
- }
153
- case ShaderUtil . ShaderPropertyType . TexEnv :
154
- {
155
- material . SetTexture ( layerPropertyName , layerMaterial . GetTexture ( propertyName ) ) ;
156
- break ;
157
- }
158
- }
159
- }
128
+
129
+ if ( ! exclusionList . Contains ( propertyName ) )
130
+ {
131
+ if ( material . HasProperty ( layerPropertyName ) )
132
+ {
133
+ ShaderUtil . ShaderPropertyType type = ShaderUtil . GetPropertyType ( layerShader , i ) ;
134
+ switch ( type )
135
+ {
136
+ case ShaderUtil . ShaderPropertyType . Color :
137
+ {
138
+ material . SetColor ( layerPropertyName , layerMaterial . GetColor ( propertyName ) ) ;
139
+ break ;
140
+ }
141
+ case ShaderUtil . ShaderPropertyType . Float :
142
+ case ShaderUtil . ShaderPropertyType . Range :
143
+ {
144
+ material . SetFloat ( layerPropertyName , layerMaterial . GetFloat ( propertyName ) ) ;
145
+ break ;
146
+ }
147
+ case ShaderUtil . ShaderPropertyType . Vector :
148
+ {
149
+ material . SetVector ( layerPropertyName , layerMaterial . GetVector ( propertyName ) ) ;
150
+ break ;
151
+ }
152
+ case ShaderUtil . ShaderPropertyType . TexEnv :
153
+ {
154
+ material . SetTexture ( layerPropertyName , layerMaterial . GetTexture ( propertyName ) ) ;
155
+ break ;
156
+ }
157
+ }
158
+ }
159
+ }
160
160
}
161
161
}
162
162
}
@@ -458,10 +458,11 @@ protected override void SetupKeywordsForInputMaps(Material material)
458
458
SetKeyword ( material , "_NORMALMAP" , material . GetTexture ( kNormalMap + i ) ) ;
459
459
SetKeyword ( material , "_MASKMAP" , material . GetTexture ( kMaskMap + i ) ) ;
460
460
SetKeyword ( material , "_SPECULAROCCLUSIONMAP" , material . GetTexture ( kSpecularOcclusionMap + i ) ) ;
461
- SetKeyword ( material , "_EMISSIVE_COLOR_MAP" , material . GetTexture ( kEmissiveColorMap + i ) ) ;
462
461
SetKeyword ( material , "_HEIGHTMAP" , material . GetTexture ( kHeightMap + i ) ) ;
462
+ SetKeyword ( material , "_DETAIL_MAP" , material . GetTexture ( kDetailMap + i ) ) ;
463
463
}
464
464
465
+ SetKeyword ( material , "_EMISSIVE_COLOR_MAP" , material . GetTexture ( kEmissiveColorMap ) ) ;
465
466
SetKeyword ( material , "_LAYER_MASK_VERTEX_COLOR" , material . GetFloat ( kLayerMaskVertexColor ) != 0.0f ) ;
466
467
}
467
468
@@ -489,9 +490,9 @@ void SetupMaterialForLayers(Material material)
489
490
{
490
491
// We setup the masking map based on the enum for each layer.
491
492
// using mapping mask allow to reduce the number of generated combination for a very small increase in ALU
492
- string layerUVBaseParam = string . Format ( "{0}{1}" , kLayerUVBase , i ) ;
493
+ string layerUVBaseParam = string . Format ( "{0}{1}" , kUVBase , i ) ;
493
494
LayerUVBaseMapping layerUVBaseMapping = ( LayerUVBaseMapping ) material . GetFloat ( layerUVBaseParam ) ;
494
- string layerUVDetailParam = string . Format ( "{0}{1}" , kLayerUVDetail , i ) ;
495
+ string layerUVDetailParam = string . Format ( "{0}{1}" , kUVDetail , i ) ;
495
496
LayerUVDetailMapping layerUVDetailMapping = ( LayerUVDetailMapping ) material . GetFloat ( layerUVDetailParam ) ;
496
497
string currentLayerMappingTriplanar = string . Format ( "{0}{1}" , kLayerMappingTriplanar , i ) ;
497
498
@@ -502,10 +503,7 @@ void SetupMaterialForLayers(Material material)
502
503
W = ( layerUVBaseMapping == LayerUVBaseMapping . Planar ) ? 1.0f : 0.0f ;
503
504
layerUVMappingMask [ i ] . colorValue = new Color ( X , Y , Z , W ) ;
504
505
505
- if ( layerUVBaseMapping == LayerUVBaseMapping . Triplanar )
506
- {
507
- SetKeyword ( material , currentLayerMappingTriplanar , true ) ;
508
- }
506
+ SetKeyword ( material , currentLayerMappingTriplanar , layerUVBaseMapping == LayerUVBaseMapping . Triplanar ) ;
509
507
510
508
// If base is planar mode, detail is planar too
511
509
if ( W > 0.0f )
0 commit comments