Exemplo n.º 1
0
        public override string GenerateShaderForOutput(int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar)
        {
            if (m_outputPorts[0].IsLocalValue(dataCollector.PortCategory))
            {
                return(m_outputPorts[0].LocalValue(dataCollector.PortCategory));
            }

            string precisionString = UIUtils.PrecisionWirePortToCgType(CurrentPrecisionType, WirePortDataType.FLOAT);
            string value           = m_inputPorts[0].GeneratePortInstructions(ref dataCollector);

            if (m_outputPorts[0].DataType == WirePortDataType.FLOAT3x3)
            {
                GeneratorUtils.Add3x3InverseFunction(ref dataCollector, precisionString);
                RegisterLocalVariable(0, string.Format(GeneratorUtils.Inverse3x3Header, value), ref dataCollector, "invertVal" + OutputId);
            }
            else
            {
                if (!dataCollector.HasFunction(Inverse4x4Header))
                {
                    //Hack to be used util indent is properly used
                    int currIndent = UIUtils.ShaderIndentLevel;

                    if (dataCollector.IsTemplate)
                    {
                        UIUtils.ShaderIndentLevel = 0;
                    }
                    else
                    {
                        UIUtils.ShaderIndentLevel = 1;
                        UIUtils.ShaderIndentLevel++;
                    }

                    string finalFunction = string.Empty;
                    for (int i = 0; i < Inverse4x4Function.Length; i++)
                    {
                        finalFunction += UIUtils.ShaderIndentTabs + (Inverse4x4FunctionFlags[i] ? string.Format(Inverse4x4Function[i], precisionString) : Inverse4x4Function[i]);
                    }


                    UIUtils.ShaderIndentLevel = currIndent;

                    dataCollector.AddFunction(Inverse4x4Header, finalFunction);
                }

                RegisterLocalVariable(0, string.Format(Inverse4x4Header, value), ref dataCollector, "invertVal" + OutputId);
            }

            return(m_outputPorts[0].LocalValue(dataCollector.PortCategory));
        }