Exemple #1
0
        public void Add_Filter()
        {
            // setup
            float addValue  = 9000f;
            var   addFilter = FilterUtility.CreateInstance <AddFilter>();

            addFilter.value = addValue;

            var prevRT = RenderTexture.active;
            var src    = RTUtils.GetTempHandle(RTUtils.GetDescriptor(1, 1, 0, GraphicsFormat.R16G16B16A16_SFloat, 0, false));
            var dest   = RTUtils.GetTempHandle(RTUtils.GetDescriptor(1, 1, 0, GraphicsFormat.R16G16B16A16_SFloat, 0, false));

            Graphics.Blit(Texture2D.blackTexture, src);
            Graphics.Blit(Texture2D.blackTexture, dest);

            // eval
            addFilter.Eval(m_Context, src, dest);

            var tex = new Texture2D(1, 1, TextureFormat.RGBAFloat, false, true);

            RenderTexture.active = dest;
            tex.ReadPixels(new Rect(0, 0, 1, 1), 0, 0, false);

            var check = tex.GetPixel(0, 0).r;

            // clean up
            RenderTexture.active = prevRT;
            UObject.DestroyImmediate(tex);
            RTUtils.Release(src);
            RTUtils.Release(dest);
            UObject.DestroyImmediate(addFilter);

            Assert.That(check, Is.EqualTo(addValue));
        }
Exemple #2
0
        public void Values_Can_Be_Negative()
        {
            // setup
            float addValue  = -10;
            var   addFilter = FilterUtility.CreateInstance <AddFilter>();

            addFilter.value = addValue;
            m_Stack.Add(addFilter);

            var prevRT = RenderTexture.active;
            var dest   = RTUtils.GetTempHandle(RTUtils.GetDescriptor(1, 1, 0, GraphicsFormat.R16G16B16A16_SFloat, 0, false));

            Graphics.Blit(Texture2D.blackTexture, dest); // init to black

            // eval
            m_Stack.Eval(m_Context, null, dest); // source isn't actually used yet

            var tex = new Texture2D(1, 1, TextureFormat.RGBAFloat, false, true);

            RenderTexture.active = dest;
            tex.ReadPixels(new Rect(0, 0, 1, 1), 0, 0, false);

            var check = tex.GetPixel(0, 0).r - 1; // minus 1 because we start off with a white texture within FilterStack.Eval

            // clean up
            RenderTexture.active = prevRT;
            UObject.DestroyImmediate(tex);
            RTUtils.Release(dest);

            Assert.That(check, Is.EqualTo(addValue));
        }
        public IEnumerator Test_PaintHeight_With_BrushMaskFilters_Playback(string recordingFilePath, string targetTerrainName)
        {
            yield return(null);

            InitTerrainTypesWithReflection("PaintHeightTool");
            onPaintHistory = LoadDataFile(recordingFilePath);
            SetupTerrain(targetTerrainName);

            commonUIInstance.brushMaskFilterStack.Clear(true);

            var filterCount = FilterUtility.GetFilterTypeCount();

            for (int i = 0; i < filterCount; ++i)
            {
                commonUIInstance.brushMaskFilterStack.Add(FilterUtility.CreateInstance(FilterUtility.GetFilterType(i)));
            }

            while (onPaintHistory.Count > 0)
            {
                // Force a SceneView update for OnSceneGUI to be triggered
                SceneView.RepaintAll();
                PaintContext.ApplyDelayedActions();
                yield return(null);
            }

            if (terrainObj.drawInstanced)
            {
                terrainObj.terrainData.SyncHeightmap();
            }
        }