void AddPreview(INode node)
        {
            var shaderData = new PreviewShaderData
            {
                node = node
            };
            var renderData = new PreviewRenderData
            {
                shaderData    = shaderData,
                renderTexture = new RenderTexture(200, 200, 16, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default)
                {
                    hideFlags = HideFlags.HideAndDontSave
                }
            };

            renderData.renderTexture.Create();
            Set(m_Identifiers, node.tempId, node.tempId);
            Set(m_RenderDatas, node.tempId, renderData);
            m_DirtyShaders.Add(node.tempId.index);
            node.RegisterCallback(OnNodeModified);
            if (node.RequiresTime())
            {
                m_TimeDependentPreviews.Add(node.tempId.index);
            }

            var masterNode = node as IMasterNode;

            if (masterRenderData.shaderData == null && masterNode != null)
            {
                masterRenderData.shaderData = shaderData;
            }
        }
Exemple #2
0
        void AddPreview(AbstractMaterialNode node)
        {
            var isMaster = false;

            if (node is IMasterNode || node is SubGraphOutputNode)
            {
                // we don't build preview render data for output nodes that aren't the active output node
                if (masterRenderData != null || (node is IMasterNode && node != node.owner.outputNode))
                {
                    return;
                }

                isMaster = true;
            }

            var renderData = new PreviewRenderData
            {
                renderTexture =
                    new RenderTexture(200, 200, 16, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default)
                {
                    hideFlags = HideFlags.HideAndDontSave
                }
            };

            if (isMaster)
            {
                m_MasterRenderData             = renderData;
                renderData.renderTexture.width = renderData.renderTexture.height = 400;
            }

            renderData.renderTexture.Create();

            var shaderData = new PreviewShaderData
            {
                node            = node,
                passesCompiling = 0,
                isOutOfDate     = true,
                hasError        = false,
            };

            renderData.shaderData = shaderData;

            m_RenderDatas.Add(node.objectId, renderData);
            node.RegisterCallback(OnNodeModified);

            if (node.RequiresTime())
            {
                m_RefreshTimedNodes = true;
            }

            if (m_MasterRenderData == renderData && onPrimaryMasterChanged != null)
            {
                onPrimaryMasterChanged();
            }

            m_NodesNeedsRecompile.Add(node);
        }
Exemple #3
0
 void CheckForErrors(PreviewShaderData shaderData)
 {
     shaderData.hasError = ShaderUtil.ShaderHasError(shaderData.shader);
     if (shaderData.hasError)
     {
         var messages = ShaderUtil.GetShaderMessages(shaderData.shader);
         if (messages.Length > 0)
         {
             m_Messenger.AddOrAppendError(this, shaderData.node.objectId, messages[0]);
         }
     }
 }
Exemple #4
0
        void AddPreview(AbstractMaterialNode node)
        {
            var renderData = new PreviewRenderData
            {
                renderTexture =
                    new RenderTexture(200, 200, 16, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default)
                {
                    hideFlags = HideFlags.HideAndDontSave
                }
            };

            if (masterRenderData == null && (node is IMasterNode || node is SubGraphOutputNode))
            {
                m_MasterRenderData             = renderData;
                renderData.renderTexture.width = renderData.renderTexture.height = 400;
            }

            renderData.renderTexture.Create();

            var shaderData = new PreviewShaderData
            {
                node        = node,
                isCompiling = false,
                hasError    = false,
                shader      = ShaderUtil.CreateShaderAsset(k_EmptyShader, false)
            };

            shaderData.shader.hideFlags = HideFlags.HideAndDontSave;
            shaderData.mat = new Material(shaderData.shader)
            {
                hideFlags = HideFlags.HideAndDontSave
            };
            renderData.shaderData = shaderData;

            Set(m_Identifiers, node.tempId, node.tempId);
            Set(m_RenderDatas, node.tempId, renderData);
            node.RegisterCallback(OnNodeModified);

            if (node.RequiresTime())
            {
                m_RefreshTimedNodes = true;
            }

            if (m_MasterRenderData == renderData && onPrimaryMasterChanged != null)
            {
                onPrimaryMasterChanged();
            }

            m_NodesToUpdate.Add(node);
        }
Exemple #5
0
        void AddPreview(INode node)
        {
            var shaderData = new PreviewShaderData
            {
                node   = node,
                shader = m_UberShader
            };
            var renderData = new PreviewRenderData
            {
                shaderData    = shaderData,
                renderTexture = new RenderTexture(200, 200, 16, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default)
                {
                    hideFlags = HideFlags.HideAndDontSave
                },
            };

            renderData.renderTexture.Create();
            Set(m_Identifiers, node.tempId, node.tempId);
            Set(m_RenderDatas, node.tempId, renderData);
            node.RegisterCallback(OnNodeModified);

            var isMaster = node is IMasterNode;

            if (masterRenderData.shaderData == null &&
                (isMaster || node is SubGraphOutputNode))
            {
                masterRenderData.shaderData = shaderData;
                // If it's actually the master, clear the shader since it will be assigned
                // later. SubGraphOutputNode still needs the UberShader.
                if (isMaster)
                {
                    masterRenderData.shaderData.shader = null;
                }
            }

            m_NeedShaderUpdate = true;
        }
Exemple #6
0
        void ProcessCompletedShaderCompilations()
        {
            // Check for shaders that finished compiling and set them to redraw
            using (ProcessCompletedShaderCompilationsMarker.Auto())
                using (var nodesCompiled = PooledHashSet <AbstractMaterialNode> .Get())
                {
                    foreach (var node in m_NodesCompiling)
                    {
                        PreviewRenderData renderData = GetPreviewRenderData(node);
                        PreviewShaderData shaderData = renderData.shaderData;
                        Assert.IsTrue(shaderData.passesCompiling > 0);

                        if (shaderData.passesCompiling != renderData.shaderData.mat.passCount)
                        {
                            // attempt to re-kick the compilation a few times
                            compileFailRekicks++;
                            if (compileFailRekicks <= 3)
                            {
                                renderData.shaderData.passesCompiling = 0;
                                m_NodesNeedsRecompile.Add(node);
                                nodesCompiled.Add(node);
                                continue;
                            }
                            else if (compileFailRekicks == 4)
                            {
                                Debug.LogWarning("Unexpected error in compiling preview shaders: some previews might not update. You can try to re-open the Shader Graph window, or select <b>Help > Report a Bug</b> in the menu and report this bug.");
                            }
                        }

                        // check that all passes have compiled
                        var allPassesCompiled = true;
                        for (var i = 0; i < renderData.shaderData.mat.passCount; i++)
                        {
                            if (!ShaderUtil.IsPassCompiled(renderData.shaderData.mat, i))
                            {
                                allPassesCompiled = false;
                                break;
                            }
                        }

                        if (!allPassesCompiled)
                        {
                            continue;
                        }

                        // Force the material to re-generate all it's shader properties, by reassigning the shader
                        renderData.shaderData.mat.shader      = renderData.shaderData.shader;
                        renderData.shaderData.passesCompiling = 0;
                        renderData.shaderData.isOutOfDate     = false;
                        CheckForErrors(renderData.shaderData);

                        nodesCompiled.Add(renderData.shaderData.node);

                        var masterNode = renderData.shaderData.node as IMasterNode;
                        masterNode?.ProcessPreviewMaterial(renderData.shaderData.mat);
                    }

                    // removed compiled nodes from compiling list
                    m_NodesCompiling.ExceptWith(nodesCompiled);

                    // and add them to the draw list
                    m_NodesToDraw.UnionWith(nodesCompiled);
                }
        }