public void ComputeHeight(ref ComputeBuffer layerBuffer, ref ComputeBuffer maskBuffer, float seedParent, bool first = false) { TC_Compute compute = TC_Compute.instance; float seedTotal = seed + seedParent; layerBuffer = selectNodeGroup.ComputeValue(seedTotal); if (layerBuffer != null) { if (maskNodeGroup.active) { maskBuffer = maskNodeGroup.ComputeValue(seedTotal); } if (maskBuffer != null) { if (method != Method.Lerp || first) { InitPreviewRenderTexture(true, "rtPreview_Layer_" + TC.outputNames[outputId]); compute.RunComputeMethod(null, null, layerBuffer, ref maskBuffer, 0, rtPreview); } } else { rtDisplay = selectNodeGroup.rtDisplay; } } else { TC_Reporter.Log("Layerbuffer " + listIndex + " = null, reporting from layer"); } }
// Compute height, trees and objects public ComputeBuffer ComputeSingle(ref ComputeBuffer totalBuffer, float seedParent, bool first = false) { if (!groupResult.active) { return(null); } TC_Compute compute = TC_Compute.instance; float seedTotal = seed + seedParent; totalBuffer = groupResult.ComputeSingle(seedTotal, first); // Debug.Log("layerMaskBuffer " + layerMaskBuffer == null); ComputeBuffer maskBuffer = null; if (maskNodeGroup.active) { maskBuffer = maskNodeGroup.ComputeValue(seedTotal); } if (maskBuffer != null) { TC_Compute.InitPreviewRenderTexture(ref rtPreview, "rtPreview_LayerGroup"); if (method != Method.Lerp || first) { if (outputId == TC.heightOutput) { compute.RunComputeMethod(null, null, totalBuffer, ref maskBuffer, 0, rtPreview); } else { compute.RunItemComputeMask(this, ref rtPreview, groupResult.rtDisplay, ref totalBuffer, ref maskBuffer); } } rtDisplay = rtPreview; } else { if (outputId == TC.heightOutput || level == 0 || groupResult.totalActive == 1) { rtDisplay = groupResult.rtDisplay; } else { rtDisplay = rtPreview; } } if (totalBuffer == null) { TC_Reporter.Log("Layer buffer null"); } return(maskBuffer); }
public ComputeBuffer ComputeValue(float seedParent) { TC_Compute compute = TC_Compute.instance; if (compute == null) { Debug.Log("Compute is null"); } ComputeBuffer nodeBuffer = null; ComputeBuffer totalBuffer = null; bool inputCurrent; if (totalActive > 1) { InitPreviewRenderTexture(true, name); } int length = useConstant ? 1 : itemList.Count; float seedTotal = seed + seedParent; for (int i = 0; i < length; i++) { TC_Node node = itemList[i] as TC_Node; if (node != null) { node.Init(); if (!node.active) { continue; } if (node.clamp) { // if (node.OutOfBounds()) continue; } inputCurrent = (node.inputKind == InputKind.Current); node.InitPreviewRenderTexture(true, node.name); if (totalBuffer == null && !inputCurrent) { totalBuffer = compute.RunNodeCompute(this, node, seedTotal); } else { if (!inputCurrent) { // Debug.Log(totalBuffer == null); nodeBuffer = compute.RunNodeCompute(this, node, seedTotal, totalBuffer, false); } else { for (int j = 0; j < node.iterations; j++) { totalBuffer = compute.RunNodeCompute(this, node, seedTotal, totalBuffer, true); } // if (preview && totalBuffer != null) { compute.DisposeBuffer(ref totalBuffer); } } // if (preview && nodeBuffer != null) { compute.DisposeBuffer(ref nodeBuffer); } } if (totalBuffer != null && nodeBuffer != null && !inputCurrent) { compute.RunComputeMethod(this, node, totalBuffer, ref nodeBuffer, itemList.Count, i == lastActive ? rtPreview : null); } } else { TC_NodeGroup nodeGroup = itemList[i] as TC_NodeGroup; if (nodeGroup != null) { if (!nodeGroup.active) { continue; } if (totalBuffer == null) { totalBuffer = nodeGroup.ComputeValue(seedTotal); } else { nodeBuffer = nodeGroup.ComputeValue(seedTotal); } if (totalBuffer != null && nodeBuffer != null) { compute.RunComputeMethod(this, nodeGroup, totalBuffer, ref nodeBuffer, itemList.Count, i == lastActive ? rtPreview : null); } } } } if (totalActive == 1) { TC_Compute.DisposeRenderTexture(ref rtPreview); rtDisplay = itemList[firstActive].rtDisplay; } if (isPortalCount > 0 && totalBuffer != null) { TC_Compute.instance.MakePortalBuffer(this, totalBuffer); } return(totalBuffer); }
// Compute height, trees and objects public ComputeBuffer ComputeSingle(float seedParent, bool first = false) { TC_Compute compute = TC_Compute.instance; ComputeBuffer totalBuffer = null; ComputeBuffer layerBuffer = null; ComputeBuffer layerMaskBuffer = null; RenderTexture[] rtsPreview = null; RenderTexture rtRightPreview = null; RenderTexture rtLeftPreview = null; if (outputId != TC.heightOutput) { rtsPreview = new RenderTexture[2]; } SetPreviewTextureBefore(); int even = 0; float seedTotal = seed + seedParent; for (int i = 0; i < itemList.Count; i++) { TC_Layer layer = itemList[i] as TC_Layer; if (layer != null) { if (!layer.active) { TC_Reporter.Log("Inactive layer " + i); continue; } if (totalBuffer == null) { if (outputId == TC.heightOutput) { layer.ComputeHeight(ref totalBuffer, ref layerMaskBuffer, seedTotal, i == firstActive); } else { layer.ComputeItem(ref totalBuffer, ref layerMaskBuffer, seedTotal, i == firstActive); if (totalBuffer != null) { rtLeftPreview = layer.rtDisplay; } } TC_Area2D.current.layerGroupBuffer = totalBuffer; // Portal compute.DisposeBuffer(ref layerMaskBuffer); } else { if (outputId == TC.heightOutput) { layer.ComputeHeight(ref layerBuffer, ref layerMaskBuffer, seedTotal); } else { layer.ComputeItem(ref layerBuffer, ref layerMaskBuffer, seedTotal); } if (layerBuffer != null) { if (outputId == TC.heightOutput) { compute.RunComputeMethod(this, layer, totalBuffer, ref layerBuffer, totalActive, i == lastActive ? rtPreview : null, layerMaskBuffer); } else { rtRightPreview = layer.rtDisplay; compute.RunComputeObjectMethod(this, layer, totalBuffer, ref layerBuffer, layerMaskBuffer, rtPreview, ref rtsPreview[even++ % 2], ref rtLeftPreview, rtRightPreview); } TC_Area2D.current.layerGroupBuffer = totalBuffer; } compute.DisposeBuffer(ref layerMaskBuffer); } } else { TC_LayerGroup layerGroup = itemList[i] as TC_LayerGroup; if (layerGroup == null) { continue; } if (!layerGroup.active) { continue; } if (totalBuffer == null) { layerMaskBuffer = layerGroup.ComputeSingle(ref totalBuffer, seedTotal, i == firstActive); if (totalBuffer != null) { rtLeftPreview = layerGroup.rtDisplay; } TC_Area2D.current.layerGroupBuffer = totalBuffer; compute.DisposeBuffer(ref layerMaskBuffer); } else { layerMaskBuffer = layerGroup.ComputeSingle(ref layerBuffer, seedTotal); if (layerBuffer != null) { if (outputId == TC.heightOutput) { compute.RunComputeMethod(this, layerGroup, totalBuffer, ref layerBuffer, totalActive, i == lastActive ? rtPreview : null, layerMaskBuffer); } else { rtRightPreview = layerGroup.rtDisplay; compute.RunComputeObjectMethod(this, layerGroup, totalBuffer, ref layerBuffer, layerMaskBuffer, rtPreview, ref rtsPreview[even++ % 2], ref rtLeftPreview, rtRightPreview); } TC_Area2D.current.layerGroupBuffer = totalBuffer; } compute.DisposeBuffer(ref layerMaskBuffer); } } } SetPreviewTextureAfter(); if (outputId != TC.heightOutput) { TC_Compute.DisposeRenderTextures(ref rtsPreview); } compute.DisposeBuffer(ref layerMaskBuffer); if (totalBuffer == null) { TC_Reporter.Log("Layer buffer null"); } return(totalBuffer); }