您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
112 行
3.9 KiB
112 行
3.9 KiB
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace UnityEditor.ShaderGraph
|
|
{
|
|
class PropertyCollector
|
|
{
|
|
public struct TextureInfo
|
|
{
|
|
public string name;
|
|
public int textureId;
|
|
public bool modifiable;
|
|
}
|
|
|
|
public readonly List<AbstractShaderProperty> properties = new List<AbstractShaderProperty>();
|
|
|
|
public void AddShaderProperty(AbstractShaderProperty chunk)
|
|
{
|
|
if (properties.Any(x => x.referenceName == chunk.referenceName))
|
|
return;
|
|
properties.Add(chunk);
|
|
}
|
|
|
|
public void GetPropertiesDeclaration(ShaderStringBuilder builder, GenerationMode mode, ConcretePrecision inheritedPrecision)
|
|
{
|
|
foreach (var prop in properties)
|
|
{
|
|
prop.ValidateConcretePrecision(inheritedPrecision);
|
|
}
|
|
|
|
var batchAll = mode == GenerationMode.Preview;
|
|
builder.AppendLine("CBUFFER_START(UnityPerMaterial)");
|
|
foreach (var prop in properties.Where(n => batchAll || (n.generatePropertyBlock && n.isBatchable)))
|
|
{
|
|
builder.AppendLine(prop.GetPropertyDeclarationString());
|
|
}
|
|
builder.AppendLine("CBUFFER_END");
|
|
builder.AppendNewLine();
|
|
|
|
if (batchAll)
|
|
return;
|
|
|
|
foreach (var prop in properties.Where(n => !n.isBatchable || !n.generatePropertyBlock))
|
|
{
|
|
builder.AppendLine(prop.GetPropertyDeclarationString());
|
|
}
|
|
}
|
|
|
|
public List<TextureInfo> GetConfiguredTexutres()
|
|
{
|
|
var result = new List<TextureInfo>();
|
|
|
|
foreach (var prop in properties.OfType<TextureShaderProperty>())
|
|
{
|
|
if (prop.referenceName != null)
|
|
{
|
|
var textureInfo = new TextureInfo
|
|
{
|
|
name = prop.referenceName,
|
|
textureId = prop.value.texture != null ? prop.value.texture.GetInstanceID() : 0,
|
|
modifiable = prop.modifiable
|
|
};
|
|
result.Add(textureInfo);
|
|
}
|
|
}
|
|
|
|
foreach (var prop in properties.OfType<Texture2DArrayShaderProperty>())
|
|
{
|
|
if (prop.referenceName != null)
|
|
{
|
|
var textureInfo = new TextureInfo
|
|
{
|
|
name = prop.referenceName,
|
|
textureId = prop.value.textureArray != null ? prop.value.textureArray.GetInstanceID() : 0,
|
|
modifiable = prop.modifiable
|
|
};
|
|
result.Add(textureInfo);
|
|
}
|
|
}
|
|
|
|
foreach (var prop in properties.OfType<Texture3DShaderProperty>())
|
|
{
|
|
if (prop.referenceName != null)
|
|
{
|
|
var textureInfo = new TextureInfo
|
|
{
|
|
name = prop.referenceName,
|
|
textureId = prop.value.texture != null ? prop.value.texture.GetInstanceID() : 0,
|
|
modifiable = prop.modifiable
|
|
};
|
|
result.Add(textureInfo);
|
|
}
|
|
}
|
|
|
|
foreach (var prop in properties.OfType<CubemapShaderProperty>())
|
|
{
|
|
if (prop.referenceName != null)
|
|
{
|
|
var textureInfo = new TextureInfo
|
|
{
|
|
name = prop.referenceName,
|
|
textureId = prop.value.cubemap != null ? prop.value.cubemap.GetInstanceID() : 0,
|
|
modifiable = prop.modifiable
|
|
};
|
|
result.Add(textureInfo);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
}
|