|
|
|
|
|
|
[Title("Output/Pixel Shader")] |
|
|
|
class PixelShaderNode : BaseMaterialNode, IGeneratesBodyCode |
|
|
|
{ |
|
|
|
private const string kAlbedoSlotName = "Albedo"; |
|
|
|
private const string kNormalSlotName = "Normal"; |
|
|
|
private const string kEmissionSlotName = "Emission"; |
|
|
|
private const string kMetallicSlotName = "Metallic"; |
|
|
|
private const string kSmoothnessSlotName = "Smoothness"; |
|
|
|
private const string kOcclusion = "Occlusion"; |
|
|
|
private const string kAlphaSlotName = "Alpha"; |
|
|
|
public const string kAlbedoSlotName = "Albedo"; |
|
|
|
public const string kSpecularSlotName = "Specular"; |
|
|
|
public const string kNormalSlotName = "Normal"; |
|
|
|
public const string kEmissionSlotName = "Emission"; |
|
|
|
public const string kMetallicSlotName = "Metallic"; |
|
|
|
public const string kSmoothnessSlotName = "Smoothness"; |
|
|
|
public const string kOcclusion = "Occlusion"; |
|
|
|
public const string kAlphaSlotName = "Alpha"; |
|
|
|
private string m_LightFunction; |
|
|
|
private string m_LightFunctionClassName; |
|
|
|
|
|
|
|
private static List<BaseLightFunction> s_LightFunctions; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AddSlot (new Slot(SlotType.InputSlot, kAlbedoSlotName)); |
|
|
|
AddSlot (new Slot(SlotType.InputSlot, kNormalSlotName)); |
|
|
|
AddSlot (new Slot(SlotType.InputSlot, kSpecularSlotName)); |
|
|
|
AddSlot (new Slot(SlotType.InputSlot, kEmissionSlotName)); |
|
|
|
AddSlot (new Slot(SlotType.InputSlot, kMetallicSlotName)); |
|
|
|
AddSlot (new Slot(SlotType.InputSlot, kSmoothnessSlotName)); |
|
|
|
|
|
|
} |
|
|
|
return s_LightFunctions; |
|
|
|
} |
|
|
|
|
|
|
|
public virtual void GenerateLightFunction (ShaderGenerator visitor) |
|
|
|
{ |
|
|
|
visitor.AddPragmaChunk (m_LightFunction); |
|
|
|
|
|
|
|
private BaseLightFunction GetLightFunction() |
|
|
|
{ |
|
|
|
var lightFunctions = GetLightFunctions(); |
|
|
|
var lightFunction = lightFunctions.FirstOrDefault(x => x.GetType().ToString() == m_LightFunctionClassName); |
|
|
|
|
|
|
|
if (lightFunction == null && lightFunctions.Count > 0) |
|
|
|
lightFunction = lightFunctions[0]; |
|
|
|
var lightFunction = GetLightFunctions().FirstOrDefault(x => x.GetName() == m_LightFunction); |
|
|
|
int lightFuncIndex = 0; |
|
|
|
if (lightFunction != null) |
|
|
|
lightFuncIndex = GetLightFunctions ().IndexOf (lightFunction); |
|
|
|
return lightFunction; |
|
|
|
} |
|
|
|
if (lightFuncIndex < s_LightFunctions.Count) |
|
|
|
{ |
|
|
|
BaseLightFunction func = s_LightFunctions[lightFuncIndex]; |
|
|
|
func.GenerateBody (visitor); |
|
|
|
} |
|
|
|
public virtual void GenerateLightFunction (ShaderGenerator visitor) |
|
|
|
{ |
|
|
|
var lightFunction = GetLightFunction(); |
|
|
|
lightFunction.GenerateLightFunctionName(visitor); |
|
|
|
lightFunction.GenerateLightFunctionBody (visitor); |
|
|
|
public void GenerateSurfaceOutput(ShaderGenerator visitor) |
|
|
|
{ |
|
|
|
var lightFunction = GetLightFunction(); |
|
|
|
lightFunction.GenerateSurfaceOutputStructureName(visitor); |
|
|
|
} |
|
|
|
|
|
|
|
public virtual IEnumerable<Slot> FilterSlotsForLightFunction() |
|
|
|
{ |
|
|
|
var lightFunction = GetLightFunction(); |
|
|
|
return lightFunction.FilterSlots(slots); |
|
|
|
} |
|
|
|
|
|
|
|
public void GenerateNodeCode(ShaderGenerator shaderBody, GenerationMode generationMode) |
|
|
|
{ |
|
|
|
// do the normal slot first so that it can be used later in the shader :)
|
|
|
|
|
|
|
(node as IGeneratesBodyCode).GenerateNodeCode(shaderBody, generationMode); |
|
|
|
} |
|
|
|
|
|
|
|
foreach (var slot in slots) |
|
|
|
foreach (var slot in FilterSlotsForLightFunction()) |
|
|
|
{ |
|
|
|
if (slot == normal) |
|
|
|
continue; |
|
|
|
|
|
|
public override void NodeUI (Graphs.GraphGUI host) |
|
|
|
{ |
|
|
|
base.NodeUI(host); |
|
|
|
var lightFunction = GetLightFunctions ().FirstOrDefault (x => x.GetName () == m_LightFunction); |
|
|
|
int lightFuncIndex = 0; |
|
|
|
var lightFunctions = GetLightFunctions(); |
|
|
|
var lightFunction = GetLightFunction(); |
|
|
|
|
|
|
|
int lightFuncIndex = 0; |
|
|
|
lightFuncIndex = GetLightFunctions ().IndexOf (lightFunction); |
|
|
|
lightFuncIndex = EditorGUILayout.Popup (lightFuncIndex, s_LightFunctions.Select(x => x.GetName ()).ToArray (), EditorStyles.popup); |
|
|
|
m_LightFunction = GetLightFunctions ()[lightFuncIndex].GetName (); |
|
|
|
lightFuncIndex = lightFunctions.IndexOf (lightFunction); |
|
|
|
|
|
|
|
lightFuncIndex = EditorGUILayout.Popup (lightFuncIndex, lightFunctions.Select(x => x.GetLightFunctionName ()).ToArray (), EditorStyles.popup); |
|
|
|
m_LightFunctionClassName = lightFunctions[lightFuncIndex].GetType().ToString(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |