public void CanUpdateBlockActiveState() { GraphData graph = new GraphData(); graph.AddContexts(); graph.InitializeOutputs(new [] { new VFXTarget() }, new BlockFieldDescriptor[] { BlockFields.SurfaceDescription.BaseColor, BlockFields.SurfaceDescription.NormalTS }); // Remove VFX target via the bitmask var vfxTarget = graph.validTargets.FirstOrDefault(x => x is VFXTarget); var targetIndex = graph.validTargets.IndexOf(vfxTarget); graph.activeTargetBitmask = graph.activeTargetBitmask >> targetIndex; graph.UpdateActiveTargets(); var activeBlocks = graph.GetActiveBlocksForAllActiveTargets(); graph.UpdateActiveBlocks(activeBlocks); // All blocks should be inactive as there are no active targets var blocks = graph.GetNodes <BlockNode>().ToList(); Assert.AreEqual(2, blocks.Count); Assert.AreEqual(BlockFields.SurfaceDescription.BaseColor, blocks[0].descriptor); Assert.AreEqual(false, blocks[0].isActive); Assert.AreEqual(BlockFields.SurfaceDescription.NormalTS, blocks[1].descriptor); Assert.AreEqual(false, blocks[1].isActive); }
public void GetTargetIndexWorks() { s_ForceVFXFakeTargetVisible = true; GraphData graph = new GraphData(); graph.AddContexts(); int targetIndex = graph.GetTargetIndexByKnownType(typeof(VFXTarget)); Assert.IsTrue(targetIndex >= 0); var vfxTarget = new VFXTarget(); graph.SetTargetActive(vfxTarget); var targetIndex2 = graph.GetTargetIndex(vfxTarget); Assert.AreEqual(targetIndex, targetIndex2); var nonActiveVFXTarget = new VFXTarget(); Assert.AreEqual(-1, graph.GetTargetIndex(nonActiveVFXTarget)); s_ForceVFXFakeTargetVisible = false; }
public void CanUpdateBlockActiveState() { s_ForceVFXFakeTargetVisible = true; GraphData graph = new GraphData(); graph.AddContexts(); graph.InitializeOutputs(new[] { new VFXTarget() }, new BlockFieldDescriptor[] { BlockFields.SurfaceDescription.BaseColor, BlockFields.SurfaceDescription.NormalTS }); // Remove VFX target var vfxTarget = graph.allPotentialTargets.FirstOrDefault(x => x is VFXTarget); graph.SetTargetInactive(vfxTarget); var activeBlocks = graph.GetActiveBlocksForAllActiveTargets(); graph.UpdateActiveBlocks(activeBlocks); // All blocks should be inactive as there are no active targets var blocks = graph.GetNodes <BlockNode>().ToList(); Assert.AreEqual(2, blocks.Count); Assert.AreEqual(BlockFields.SurfaceDescription.BaseColor, blocks[0].descriptor); Assert.AreEqual(false, blocks[0].isActive); Assert.AreEqual(BlockFields.SurfaceDescription.NormalTS, blocks[1].descriptor); Assert.AreEqual(false, blocks[1].isActive); s_ForceVFXFakeTargetVisible = false; }
public void CanCreateBlankGraph() { GraphData graph = new GraphData(); graph.AddContexts(); Assert.IsNotNull(graph.activeTargets); Assert.AreEqual(0, graph.activeTargets.Count()); }
public void CanGatherBlockDescriptors() { GraphData graph = new GraphData(); graph.AddContexts(); Assert.IsNotNull(graph.blockFieldDescriptors); Assert.AreNotEqual(0, graph.blockFieldDescriptors.Count); }
public void CanInitializeOutputTargets() { GraphData graph = new GraphData(); graph.AddContexts(); graph.InitializeOutputs(new [] { new VFXTarget() }, null); Assert.IsNotNull(graph.activeTargets); Assert.AreEqual(1, graph.activeTargets.Count()); Assert.AreEqual(typeof(VFXTarget), graph.activeTargets.ElementAt(0).GetType()); }
public void CanGetBlockIndex() { GraphData graph = new GraphData(); graph.AddContexts(); var node = new BlockNode(); node.Init(s_DescriptorA); graph.AddBlock(node, graph.fragmentContext, 0); Assert.AreEqual(0, node.index); }
public void ActiveTargetsArePotentialTargets() { s_ForceVFXFakeTargetVisible = true; GraphData graph = new GraphData(); graph.AddContexts(); var vfxTarget = new VFXTarget(); graph.SetTargetActive(vfxTarget); Assert.IsTrue(graph.allPotentialTargets.Contains(vfxTarget)); s_ForceVFXFakeTargetVisible = false; }
public void CanAddBlockNodeToContext() { GraphData graph = new GraphData(); graph.AddContexts(); var node = new BlockNode(); node.Init(s_DescriptorA); graph.AddBlock(node, graph.fragmentContext, 0); Assert.AreEqual(0, graph.edges.Count()); Assert.AreEqual(1, graph.GetNodes <BlockNode>().Count()); Assert.AreEqual(1, graph.fragmentContext.blocks.Count()); }
public void CanAddTarget() { s_ForceVFXFakeTargetVisible = true; GraphData graph = new GraphData(); graph.AddContexts(); var vfxTarget = graph.allPotentialTargets.FirstOrDefault(x => x is VFXTarget); graph.SetTargetActive(vfxTarget); Assert.IsNotNull(graph.activeTargets); Assert.AreEqual(1, graph.activeTargets.Count()); Assert.AreEqual(vfxTarget, graph.activeTargets.ElementAt(0)); s_ForceVFXFakeTargetVisible = false; }
public void CanSetBlockActive() { GraphData graph = new GraphData(); graph.AddContexts(); graph.InitializeOutputs(new [] { new VFXTarget() }, new BlockFieldDescriptor[] { BlockFields.SurfaceDescription.BaseColor, BlockFields.SurfaceDescription.NormalTS }); // Block active state should match VFX Target's default GetActiveBlocks var blocks = graph.GetNodes <BlockNode>().ToList(); Assert.AreEqual(2, blocks.Count); Assert.AreEqual(BlockFields.SurfaceDescription.BaseColor, blocks[0].descriptor); Assert.AreEqual(true, blocks[0].isActive); Assert.AreEqual(BlockFields.SurfaceDescription.NormalTS, blocks[1].descriptor); Assert.AreEqual(false, blocks[1].isActive); }
public void CanAddTarget() { GraphData graph = new GraphData(); graph.AddContexts(); // Add VFX target via the bitmask var vfxTarget = graph.validTargets.FirstOrDefault(x => x is VFXTarget); var targetIndex = graph.validTargets.IndexOf(vfxTarget); graph.activeTargetBitmask = 1 << targetIndex; graph.UpdateActiveTargets(); Assert.IsNotNull(graph.activeTargets); Assert.AreEqual(1, graph.activeTargets.Count()); Assert.AreEqual(vfxTarget, graph.activeTargets.ElementAt(0)); }
public void CanRemoveTarget() { s_ForceVFXFakeTargetVisible = true; GraphData graph = new GraphData(); graph.AddContexts(); var vfxTarget = new VFXTarget(); graph.InitializeOutputs(new[] { vfxTarget }, null); graph.SetTargetInactive(vfxTarget); Assert.IsNotNull(graph.activeTargets); Assert.AreEqual(0, graph.activeTargets.Count()); s_ForceVFXFakeTargetVisible = false; }
public void CanRemoveTarget() { GraphData graph = new GraphData(); graph.AddContexts(); graph.InitializeOutputs(new [] { new VFXTarget() }, null); // Remove VFX target via the bitmask var vfxTarget = graph.validTargets.FirstOrDefault(x => x is VFXTarget); var targetIndex = graph.validTargets.IndexOf(vfxTarget); graph.activeTargetBitmask = graph.activeTargetBitmask >> targetIndex; graph.UpdateActiveTargets(); Assert.IsNotNull(graph.activeTargets); Assert.AreEqual(0, graph.activeTargets.Count()); }
public void CanInsertBlockNodeToContext() { GraphData graph = new GraphData(); graph.AddContexts(); var nodeA = new BlockNode(); nodeA.Init(s_DescriptorA); graph.AddBlock(nodeA, graph.fragmentContext, 0); var nodeB = new BlockNode(); nodeB.Init(s_DescriptorA); graph.AddBlock(nodeB, graph.fragmentContext, 0); Assert.AreEqual(0, graph.edges.Count()); Assert.AreEqual(2, graph.GetNodes <BlockNode>().Count()); Assert.AreEqual(2, graph.fragmentContext.blocks.Count()); Assert.AreEqual(nodeB, graph.fragmentContext.blocks[0].value); }
public void CanBuildMultipleShaders() { GraphData graph = new GraphData(); graph.AddContexts(); var multiTarget = new MultiShaderTarget(); graph.SetTargetActive(multiTarget); Assert.IsTrue(graph.allPotentialTargets.Contains(multiTarget)); graph.OnEnable(); graph.ValidateGraph(); var generator = new Generator(graph, graph.outputNode, GenerationMode.ForReals, "MyTestShader"); var generatedShaders = generator.allGeneratedShaders.ToList(); Assert.AreEqual(2, generatedShaders.Count); Assert.IsTrue(generatedShaders[0].shaderName == "MyTestShader"); Assert.IsTrue(generatedShaders[1].shaderName == "MyTestShader-second"); Assert.IsTrue(generatedShaders[0].codeString.Contains("Shader \"MyTestShader\"")); Assert.IsTrue(generatedShaders[1].codeString.Contains("Shader \"MyTestShader-second\"")); // save graph to file on disk and import it... var path = AssetDatabase.GenerateUniqueAssetPath("Assets/multiShaderTest.ShaderGraph"); FileUtilities.WriteShaderGraphToDisk(path, graph); AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceSynchronousImport | ImportAssetOptions.ForceUpdate | ImportAssetOptions.DontDownloadFromCacheServer); // check that we actually have two shader assets in the import result // (they won't work, but they should exist) var assets = AssetDatabase.LoadAllAssetsAtPath(path); int shaderCount = assets.OfType <Shader>().Count(); Assert.AreEqual(2, shaderCount); AssetDatabase.DeleteAsset(path); }
public void CanFilterBlockNodeByShaderStage() { GraphData graph = new GraphData(); graph.AddContexts(); var node = new BlockNode(); node.Init(s_DescriptorA); var contextView = new ContextView("Test", graph.vertexContext, null); var methodInfo = typeof(StackNode).GetMethod("AcceptsElement", BindingFlags.Instance | BindingFlags.NonPublic, null, new[] { typeof(GraphElement), typeof(int).MakeByRefType(), typeof(int) }, null); Assert.IsNotNull(methodInfo); var acceptsElement = (bool)methodInfo.Invoke(contextView, new object[] { new MaterialNodeView() { userData = node }, 0, 0 }); Assert.IsFalse(acceptsElement); }