public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar) { string src = m_inputPorts[0].GeneratePortInstructions(ref dataCollector); bool isScaledNormal = false; if (m_inputPorts[1].IsConnected) { isScaledNormal = true; } else { if (m_inputPorts[1].FloatInternalData != 1) { isScaledNormal = true; } } string normalMapUnpackMode = string.Empty; string scaleValue = isScaledNormal?m_inputPorts[1].GeneratePortInstructions(ref dataCollector):"1.0"; normalMapUnpackMode = GeneratorUtils.GenerateUnpackNormalStr(ref dataCollector, CurrentPrecisionType, UniqueId, OutputId, src, isScaledNormal, scaleValue); if (isScaledNormal && !(dataCollector.IsTemplate && dataCollector.IsSRP)) { dataCollector.AddToIncludes(UniqueId, Constants.UnityStandardUtilsLibFuncs); } int outputUsage = 0; for (int i = 0; i < m_outputPorts.Count; i++) { if (m_outputPorts[i].IsConnected) { outputUsage += 1; } } if (outputUsage > 1 && !dataCollector.IsSRP) { string varName = "localUnpackNormal" + OutputId; dataCollector.AddLocalVariable(UniqueId, "float3 " + varName + " = " + normalMapUnpackMode + ";"); return(GetOutputVectorItem(0, outputId, varName)); } else { return(GetOutputVectorItem(0, outputId, normalMapUnpackMode)); } }
public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar) { if (m_outputPorts[0].IsLocalValue(dataCollector.PortCategory)) { return(GetOutputVectorItem(0, outputId, m_outputPorts[0].LocalValue(dataCollector.PortCategory))); } OnPropertyNameChanged(); if (CheckReference()) { OrderIndex = m_referenceSampler.RawOrderIndex; OrderIndexOffset = m_referenceSampler.OrderIndexOffset; } bool isVertex = (dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation); bool instanced = false; if (m_referenceType == TexReferenceType.Instance && m_referenceSampler != null) { instanced = true; } if (instanced) { if (!m_referenceSampler.TexPort.IsConnected) { base.GenerateShaderForOutput(outputId, ref dataCollector, ignoreLocalvar); } } else if (!m_texPort.IsConnected) { base.GenerateShaderForOutput(outputId, ref dataCollector, ignoreLocalvar); } string level = string.Empty; if (m_lodPort.Visible) { level = m_lodPort.GeneratePortInstructions(ref dataCollector); } if (isVertex && !m_lodPort.Visible) { level = "0"; } string propertyName = string.Empty; if (instanced) { if (m_referenceSampler.TexPort.IsConnected) { propertyName = m_referenceSampler.TexPort.GeneratePortInstructions(ref dataCollector); } else { propertyName = m_referenceSampler.PropertyName; } } else if (m_texPort.IsConnected) { propertyName = m_texPort.GeneratePortInstructions(ref dataCollector); } else { propertyName = PropertyName; } string uvs = string.Empty; if (m_uvPort.IsConnected) { uvs = m_uvPort.GeneratePortInstructions(ref dataCollector); } else { if (dataCollector.IsTemplate) { uvs = dataCollector.TemplateDataCollectorInstance.GetTextureCoord(m_uvSet, propertyName /*( instanced ? m_referenceSampler.PropertyName : PropertyName )*/, UniqueId, CurrentPrecisionType); } else { if (isVertex) { uvs = TexCoordVertexDataNode.GenerateVertexUVs(ref dataCollector, UniqueId, m_uvSet, propertyName); } else { uvs = TexCoordVertexDataNode.GenerateFragUVs(ref dataCollector, UniqueId, m_uvSet, propertyName); } } } string index = m_indexPort.GeneratePortInstructions(ref dataCollector); string result = string.Empty; if (dataCollector.IsTemplate && dataCollector.IsSRP) { //CAREFUL mipbias here means derivative (this needs index changes) //TODO: unity now supports bias as well if (m_mipMode == MipType.MipBias) { dataCollector.UsingArrayDerivatives = true; result = propertyName + ".SampleGrad(sampler" + propertyName + ", float3(" + uvs + ", " + index + "), " + m_ddxPort.GeneratePortInstructions(ref dataCollector) + ", " + m_ddyPort.GeneratePortInstructions(ref dataCollector) + ");"; } else if (m_lodPort.Visible || isVertex) { result = "SAMPLE_TEXTURE2D_ARRAY_LOD(" + propertyName + ", sampler" + propertyName + ", " + uvs + ", " + index + ", " + level + " )"; } else { result = "SAMPLE_TEXTURE2D_ARRAY(" + propertyName + ", sampler" + propertyName + ", " + uvs + ", " + index + " )"; } } else { //CAREFUL mipbias here means derivative (this needs index changes) if (m_mipMode == MipType.MipBias) { dataCollector.UsingArrayDerivatives = true; result = "ASE_SAMPLE_TEX2DARRAY_GRAD(" + propertyName + ", float3(" + uvs + ", " + index + "), " + m_ddxPort.GeneratePortInstructions(ref dataCollector) + ", " + m_ddyPort.GeneratePortInstructions(ref dataCollector) + " )"; } else if (m_lodPort.Visible || isVertex) { result = "UNITY_SAMPLE_TEX2DARRAY_LOD(" + propertyName + ", float3(" + uvs + ", " + index + "), " + level + " )"; } else { result = "UNITY_SAMPLE_TEX2DARRAY" + (m_lodPort.Visible || isVertex ? "_LOD" : "") + "(" + propertyName + ", float3(" + uvs + ", " + index + ") " + (m_lodPort.Visible || isVertex ? ", " + level : "") + " )"; } } if (m_autoUnpackNormals) { bool isScaledNormal = false; if (m_normalPort.IsConnected) { isScaledNormal = true; } else { if (m_normalPort.FloatInternalData != 1) { isScaledNormal = true; } } string scaleValue = isScaledNormal ? m_normalPort.GeneratePortInstructions(ref dataCollector) : "1.0"; result = GeneratorUtils.GenerateUnpackNormalStr(ref dataCollector, CurrentPrecisionType, UniqueId, OutputId, result, isScaledNormal, scaleValue); if (isScaledNormal && (!dataCollector.IsTemplate || !dataCollector.IsSRP)) { dataCollector.AddToIncludes(UniqueId, Constants.UnityStandardUtilsLibFuncs); } } RegisterLocalVariable(0, result, ref dataCollector, "texArray" + OutputId); return(GetOutputVectorItem(0, outputId, m_outputPorts[0].LocalValue(dataCollector.PortCategory))); }