예제 #1
0
        public StarBackground()
        {
            rnd = new Random();

            //img = Raylib.GenImageColor(MoonVars.RenderWidth, MoonVars.RenderHeight, new Color(0, 0, 0, 0));
            //texture = Raylib.LoadTextureFromImage(img);
            //
            texture = Raylib.LoadRenderTexture(MoonVars.RenderWidth, MoonVars.RenderHeight);

            Color[] c = new Color[9];
            c[1] = new Color(255, 255, 255, 150);
            c[3] = new Color(255, 255, 255, 150);
            c[4] = Color.DARKGRAY;
            c[5] = new Color(255, 255, 255, 150);
            c[7] = new Color(255, 255, 255, 150);

            star    = Raylib.LoadImageEx(c, 3, 3);
            starTex = Raylib.LoadTextureFromImage(star);

            c = new Color[9];

            c[0] = Color.DARKGRAY;
            c[2] = Color.DARKGRAY;
            c[4] = Color.DARKGRAY;
            c[6] = Color.DARKGRAY;
            c[8] = Color.DARKGRAY;

            star      = Raylib.LoadImageEx(c, 3, 3);
            starTex90 = Raylib.LoadTextureFromImage(star);
            _render();
        }
    public static MultiGridLinearSolver2D Build(int maxLevel, int finerWidth, int finerHeight,
                                                RenderTexture2D level0Pressure, RenderTexture2D level0PressureSwap,
                                                RenderTexture2D level0Marker, RenderTexture2D level0Divergence,
                                                RenderTexture2D level0Levelset)
    {
        MultiGridLinearSolver2D multiGridSolver = new MultiGridLinearSolver2D();

        multiGridSolver.mMaxLevel             = maxLevel;
        multiGridSolver.mCellMakerArray       = new RenderTexture2D[maxLevel];
        multiGridSolver.mResidualTexArray     = new RenderTexture2D[maxLevel];
        multiGridSolver.mErrorTexArray        = new RenderTexture2D[maxLevel];
        multiGridSolver.mErrorTexSwapArray    = new RenderTexture2D[maxLevel];
        multiGridSolver.mRightPoissonTexArray = new RenderTexture2D[maxLevel];
        multiGridSolver.mLevelsetArray        = new RenderTexture2D[maxLevel];
        // sets level0
        multiGridSolver.mRightPoissonTexArray[0] = level0Divergence;
        multiGridSolver.mCellMakerArray[0]       = level0Marker;
        multiGridSolver.mResidualTexArray[0]     = new RenderTexture2D(finerWidth, finerHeight, "MG_Residual" + 0.ToString());
        multiGridSolver.mErrorTexArray[0]        = level0Pressure;
        multiGridSolver.mErrorTexSwapArray[0]    = level0PressureSwap;
        multiGridSolver.mLevelsetArray[0]        = level0Levelset;
        for (int i = 1; i < maxLevel; i++)
        {
            int currentWidth  = finerWidth >> i;
            int currentHeight = finerHeight >> i;
            multiGridSolver.mCellMakerArray[i]       = new RenderTexture2D(currentWidth, currentHeight, "MG_CellMarker" + i.ToString(), RenderTextureFormat.RInt);
            multiGridSolver.mLevelsetArray[i]        = new RenderTexture2D(currentWidth, currentHeight, "MG_Levelset" + i.ToString());
            multiGridSolver.mResidualTexArray[i]     = new RenderTexture2D(currentWidth, currentHeight, "MG_Residual" + i.ToString());
            multiGridSolver.mErrorTexArray[i]        = new RenderTexture2D(currentWidth, currentHeight, "MG_Error" + i.ToString());
            multiGridSolver.mErrorTexSwapArray[i]    = new RenderTexture2D(currentWidth, currentHeight, "MG_ErrorSwap" + i.ToString());
            multiGridSolver.mRightPoissonTexArray[i] = new RenderTexture2D(currentWidth, currentHeight, "MG_RightPoisson" + i.ToString());
        }
        return(multiGridSolver);
    }
    private void Restrict(RenderTexture2D sourceTex, RenderTexture2D destTex, RestrictType restrictType)
    {
        if (restrictType == RestrictType.Normal)
        {
            int MGRestrictionHalfWeightingKernel = mComputeRestrict.FindKernel("MGRestrictionHalfWeighting");
            int WIDTH  = destTex.Width;
            int HEIGHT = destTex.Height;

            mComputeRestrict.SetInt("_currentXSize", WIDTH);
            mComputeRestrict.SetInt("_currentYSize", HEIGHT);
            mComputeRestrict.SetTexture(MGRestrictionHalfWeightingKernel, "gSourceTex", sourceTex.Source);
            mComputeRestrict.SetTexture(MGRestrictionHalfWeightingKernel, "gDestinationHalfTex", destTex.Source);
            mComputeRestrict.Dispatch(MGRestrictionHalfWeightingKernel, Mathf.CeilToInt(WIDTH * 1.0f / mGroupThreadSizeX), Mathf.CeilToInt(HEIGHT * 1.0f / mGroupThreadSizeX), 1);
        }
        else if (restrictType == RestrictType.Marker)
        {
            int MGRestrictionForCellMarkerKernel = mComputeRestrict.FindKernel("MGRestrictionForCellMarker");
            int WIDTH  = destTex.Width;
            int HEIGHT = destTex.Height;

            mComputeRestrict.SetInt("_currentXSize", WIDTH);
            mComputeRestrict.SetInt("_currentYSize", HEIGHT);
            mComputeRestrict.SetTexture(MGRestrictionForCellMarkerKernel, "gSourceMarkerTex", sourceTex.Source);
            mComputeRestrict.SetTexture(MGRestrictionForCellMarkerKernel, "gDestinationHalfMarkerTex", destTex.Source);
            mComputeRestrict.Dispatch(MGRestrictionForCellMarkerKernel, Mathf.CeilToInt(WIDTH * 1.0f / mGroupThreadSizeX), Mathf.CeilToInt(HEIGHT * 1.0f / mGroupThreadSizeX), 1);
        }
    }
        void OMBackBuffer_Resized(Graphics.RenderTarget renderTarget)
        {
            var device = GraphicDeviceFactory.Device;
            int width  = renderTarget.Width;
            int height = renderTarget.Height;

            //positionRT = new RenderTexture2D(width, height, Format.R32G32B32A32_FLOAT);
            //positionRT = new RenderTexture2D(width, height, Format.R16G16B16A16_FLOAT);
            _positionRt = new RenderTexture2D(width, height, Format.R16G16B16A16_UNORM);
            _normalRt   = new RenderTexture2D(width, height, Format.R16G16B16A16_UNORM);
            _diffuseRt  = new RenderTexture2D(width, height, Format.R8G8B8A8_UNORM);
            _specularRt = new RenderTexture2D(width, height, Format.R8G8B8A8_UNORM);

            _renderTargets = new RenderTarget[]
            {
                _positionRt.Target,
                _normalRt.Target,
                _diffuseRt.Target,
                _specularRt.Target
            };
            _textures = new Texture2D[]
            {
                _positionRt.Texture,
                _normalRt.Texture,
                _diffuseRt.Texture,
                _specularRt.Texture
            };
        }
    private void Smooth(int curLevel, float SORWeight, int numLoop)
    {
        int jacobiSORKernel = mComputePressure.FindKernel("ComputeJacobiPressureSOR");

        mComputePressure.SetFloat("_SORWeight", SORWeight);
        int WIDTH  = mErrorTexArray[curLevel].Width;
        int HEIGHT = mErrorTexArray[curLevel].Height;

        mComputePressure.SetInt("_currentXSize", WIDTH);
        mComputePressure.SetInt("_currentYSize", HEIGHT);
        mComputePressure.SetInt("_currentMGLevel", curLevel);
        RenderTexture2D pressureRead  = mErrorTexArray[curLevel];
        RenderTexture2D pressureWrite = mErrorTexSwapArray[curLevel];

        //int clearTexKernl = mComputePressure.FindKernel("ClearTex");
        //mComputePressure.SetTexture(clearTexKernl, "gPressure", pressureRead.Source);
        //mComputePressure.Dispatch(clearTexKernl, Mathf.CeilToInt(WIDTH * 1.0f / mGroupThreadSizeX), Mathf.CeilToInt(HEIGHT * 1.0f / mGroupThreadSizeX), 1);

        for (int i = 0; i < numLoop; i++)
        {
            pressureRead  = i % 2 == 0 ? mErrorTexArray[curLevel] : mErrorTexSwapArray[curLevel];
            pressureWrite = i % 2 == 0 ? mErrorTexSwapArray[curLevel] : mErrorTexArray[curLevel];
            mComputePressure.SetTexture(jacobiSORKernel, "gPressure", pressureRead.Source);
            mComputePressure.SetTexture(jacobiSORKernel, "gPressureWrite", pressureWrite.Source);
            mComputePressure.SetTexture(jacobiSORKernel, "gVelocityDivergence", mRightPoissonTexArray[curLevel].Source);
            mComputePressure.SetTexture(jacobiSORKernel, "gLevelSet", mLevelsetArray[curLevel].Source);
            mComputePressure.SetTexture(jacobiSORKernel, "gCurentLevelGridMarker", mCellMakerArray[curLevel].Source);
            mComputePressure.Dispatch(jacobiSORKernel, Mathf.CeilToInt(WIDTH * 1.0f / mGroupThreadSizeX), Mathf.CeilToInt(HEIGHT * 1.0f / mGroupThreadSizeX), 1);
        }
        if (pressureRead != mErrorTexArray[curLevel])
        {
            Graphics.CopyTexture(pressureRead.Source, mErrorTexArray[curLevel].Source);
        }
    }
    private void Swap(RenderTexture2D tex0, RenderTexture2D tex1)
    {
        RenderTexture2D temp = tex0;

        tex0 = tex1;
        tex1 = temp;
    }
예제 #7
0
 static public void Initiate(Scene scene)         //initiate inside a specified scene
 {
     cM   = scene.GetCollisionManager();
     list = cM.GetObjectList();
     lineOfSightTexture = LoadRenderTexture((int)Game.screenWidth * 2, (int)Game.screenHeight * 2);
     screenOffset       = new Vector2(-Game.screenWidth, -Game.screenHeight);
 }
예제 #8
0
        public void Draw(RenderTexture2D target)
        {
            Raylib.BeginDrawing();
            {
                Raylib.BeginTextureMode(target);

                Raylib.ClearBackground(new Color(36, 36, 36, 255));

                Raylib.DrawTextEx(
                    font, MoonVars.Name,
                    new Vector2(
                        Text.Center(MoonVars.RenderWidth, (int)textMeasure.X),
                        MoonVars.RenderHeight / 4
                        ),
                    fontSize, 1, new Color(196, 196, 196, 255)
                    );

                Raylib.DrawTextEx(
                    instructFont, "Press Enter to Start",
                    new Vector2(
                        Text.Center(MoonVars.RenderWidth, (int)instructMeasure.X),
                        MoonVars.RenderHeight / 4 * 3
                        ),
                    instructFontSize, 1, Color.DARKBLUE
                    );

                stars.Draw();

                Raylib.EndTextureMode();
            }
            Raylib.EndDrawing();
        }
예제 #9
0
 /* Safe Release */
 public static void SafeRelease(RenderTexture2D renderTexture)
 {
     if (renderTexture != null)
     {
         renderTexture.Release();
     }
 }
    public void DebugComputePressure()
    {
        int jacobiKernel = mComputePressure.FindKernel("ComputeJacobiPressureSOR");

        mComputePressure.SetFloat("_SORWeight", 1.0f);
        int WIDTH  = mErrorTexArray[0].Width;
        int HEIGHT = mErrorTexArray[0].Height;

        mComputePressure.SetInt("_currentXSize", WIDTH);
        mComputePressure.SetInt("_currentYSize", HEIGHT);
        // 1. compute pressure
        int             numLoop       = 100;
        RenderTexture2D pressureRead  = mErrorTexArray[0];
        RenderTexture2D pressureWrite = mErrorTexSwapArray[0];

        for (int i = 0; i < numLoop; i++)
        {
            pressureRead  = i % 2 == 0 ? mErrorTexArray[0] : mErrorTexSwapArray[0];
            pressureWrite = i % 2 == 0 ? mErrorTexSwapArray[0] : mErrorTexArray[0];
            mComputePressure.SetTexture(jacobiKernel, "gPressure", pressureRead.Source);
            mComputePressure.SetTexture(jacobiKernel, "gPressureWrite", pressureWrite.Source);
            mComputePressure.SetTexture(jacobiKernel, "gVelocityDivergence", mRightPoissonTexArray[0].Source);
            mComputePressure.SetTexture(jacobiKernel, "gLevelSet", mLevelsetArray[0].Source);
            mComputePressure.SetTexture(jacobiKernel, "gCurentLevelGridMarker", mCellMakerArray[0].Source);
            mComputePressure.Dispatch(jacobiKernel, Mathf.CeilToInt(mErrorTexArray[0].Width * 1.0f / mGroupThreadSizeX), Mathf.CeilToInt(mErrorTexArray[0].Height * 1.0f / mGroupThreadSizeX), 1);
            //Swap(pressureRead, pressureWrite);
        }
        if (pressureRead != mErrorTexArray[0])
        {
            Graphics.CopyTexture(pressureRead.Source, mErrorTexArray[0].Source);
        }
    }
        public void Initialize()
        {
            if (_blendState == null)
            {
                _blendState    = DefaultTechnique.NoBlend;
                _rasterizer    = DefaultTechnique.NoCulling;
                _detpthStencil = DefaultTechnique.DephtState;
            }

            _texCoordOffset  = new Vector4[EngineState.Shadow.ShadowMapping.PcfBlurSize * EngineState.Shadow.ShadowMapping.PcfBlurSize];
            _texCoordWeights = new float[EngineState.Shadow.ShadowMapping.PcfBlurSize * EngineState.Shadow.ShadowMapping.PcfBlurSize];

            if (camera == null)
            {
                camera = new Camera()
                {
                    ZNear       = 1,
                    ZFar        = 1000,
                    AspectRatio = 1,
                    FieldOfView = Numerics.PIover2,
                    Type        = ProjectionType.Perspective
                };
            }
            camera.CommitChanges();

            GenerateSamples();

            ShadowMap = new RenderTexture2D(size, size, Format.R32_FLOAT, Format.D16_UNORM);
            _vp       = new ViewPort(0, 0, size, size);
            Rendered  = false;
        }
예제 #12
0
        public static int Main()
        {
            // Initialization
            //--------------------------------------------------------------------------------------
            const int screenWidth  = 800;
            const int screenHeight = 450;

            InitWindow(screenWidth, screenHeight, "raylib [shaders] example - Sieve of Eratosthenes");

            RenderTexture2D target = LoadRenderTexture(screenWidth, screenHeight);

            // Load Eratosthenes shader
            // NOTE: Defining 0 (NULL) for vertex shader forces usage of internal default vertex shader
            Shader shader = LoadShader(null, string.Format("resources/shaders/glsl{0}/eratosthenes.fs", GLSL_VERSION));

            SetTargetFPS(60);               // Set our game to run at 60 frames-per-second
            //--------------------------------------------------------------------------------------

            // Main game loop
            while (!WindowShouldClose())    // Detect window close button or ESC key
            {
                // Update
                //----------------------------------------------------------------------------------
                // Nothing to do here, everything is happening in the shader
                //----------------------------------------------------------------------------------

                // Draw
                //----------------------------------------------------------------------------------
                BeginDrawing();
                ClearBackground(RAYWHITE);

                BeginTextureMode(target); // Enable drawing to texture
                ClearBackground(BLACK);   // Clear the render texture

                // Draw a rectangle in shader mode to be used as shader canvas
                // NOTE: Rectangle uses font white character texture coordinates,
                // so shader can not be applied here directly because input vertexTexCoord
                // do not represent full screen coordinates (space where want to apply shader)
                DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), BLACK);
                EndTextureMode();           // End drawing to texture (now we have a blank texture available for the shader)

                BeginShaderMode(shader);
                // NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
                DrawTextureRec(target.texture, new Rectangle(0, 0, target.texture.width, -target.texture.height), new Vector2(0.0f, 0.0f), WHITE);
                EndShaderMode();

                EndDrawing();
                //----------------------------------------------------------------------------------
            }

            // De-Initialization
            //--------------------------------------------------------------------------------------
            UnloadShader(shader);           // Unload shader
            UnloadRenderTexture(target);    // Unload texture

            CloseWindow();                  // Close window and OpenGL context
            //--------------------------------------------------------------------------------------

            return(0);
        }
예제 #13
0
        public static void DrawRenderTexture(RenderTexture2D target)
        {
            int screenWidth  = GetScreenWidth();
            int screenHeight = GetScreenHeight();

            // NOTE: Render texture must be y-flipped due to default OpenGL coordinates (left-bottom)
            DrawTexturePro(target.texture, new Rectangle(0, 0, target.texture.width, -target.texture.height), new Rectangle(0, 0, screenWidth, screenHeight), new Vector2(0, 0), 0, Color.WHITE);
        }
예제 #14
0
        protected override void OnDraw(RenderTexture2D dst, RenderTexture2D src)
        {
            // マテリアル内の変数を設定する
            material.SetFloat("time", stopwatch.ElapsedMilliseconds * 0.001f);

            // マテリアルの内容を出力する
            DrawOnTexture2DWithMaterial(dst, material);
        }
예제 #15
0
        /// <summary>
        /// Creates the scene camera and updates the render texture. Should be called at least once before using the
        /// scene view. Should be called whenever the window is resized.
        /// </summary>
        /// <param name="width">Width of the scene render target, in pixels.</param>
        /// <param name="height">Height of the scene render target, in pixels.</param>
        private void UpdateRenderTexture(int width, int height)
        {
            width  = MathEx.Max(20, width);
            height = MathEx.Max(20, height);

            // Note: Depth buffer is required because ScenePicking uses it
            renderTexture          = new RenderTexture2D(PixelFormat.R8G8B8A8, width, height, 1, false, true);
            renderTexture.Priority = 1;

            if (camera == null)
            {
                SceneObject sceneCameraSO = new SceneObject("SceneCamera", true);
                camera              = sceneCameraSO.AddComponent <Camera>();
                camera.Target       = renderTexture;
                camera.ViewportRect = new Rect2(0.0f, 0.0f, 1.0f, 1.0f);

                sceneCameraSO.Position = new Vector3(0, 0.5f, 1);
                sceneCameraSO.LookAt(new Vector3(0, 0.5f, 0));

                camera.Priority      = 2;
                camera.NearClipPlane = 0.05f;
                camera.FarClipPlane  = 2500.0f;
                camera.ClearColor    = ClearColor;
                camera.Layers        = UInt64.MaxValue & ~SceneAxesHandle.LAYER; // Don't draw scene axes in this camera

                cameraController = sceneCameraSO.AddComponent <SceneCamera>();

                renderTextureGUI = new GUIRenderTexture(renderTexture);
                rtPanel.AddElement(renderTextureGUI);

                sceneGrid      = new SceneGrid(camera);
                sceneSelection = new SceneSelection(camera);
                sceneGizmos    = new SceneGizmos(camera);
                sceneHandles   = new SceneHandles(this, camera);
            }
            else
            {
                camera.Target = renderTexture;
                renderTextureGUI.RenderTexture = renderTexture;
            }

            Rect2I rtBounds = new Rect2I(0, 0, width, height);

            renderTextureGUI.Bounds = rtBounds;
            focusCatcher.Bounds     = GUILayoutUtility.CalculateBounds(rtPanel, GUI);

            sceneAxesGUI.SetPosition(width - HandleAxesGUISize - HandleAxesGUIPaddingX, HandleAxesGUIPaddingY);

            // TODO - Consider only doing the resize once user stops resizing the widget in order to reduce constant
            // render target destroy/create cycle for every single pixel.

            camera.AspectRatio = width / (float)height;

            if (profilerCamera != null)
            {
                profilerCamera.Target = renderTexture;
            }
        }
예제 #16
0
        protected override void OnDraw(RenderTexture2D dst, RenderTexture2D src)
        {
            // 変数の設定
            Material.SetVector2DF("resolution", Engine.WindowSize.To2DF());
            Material.SetFloat("time", Stopwatch.ElapsedMilliseconds * 0.001f);

            // マテリアルを用いて描画
            DrawOnTexture2DWithMaterial(dst, Material);
        }
예제 #17
0
        public MoonshotGame()
        {
            Raylib.InitWindow(MoonVars.ScreenWidth, MoonVars.ScreenHeight, "Moonshot - " + MoonVars.Version);
            Raylib.SetTargetFPS(MoonVars.TargetFPS);
            Raylib.SetExitKey(KeyboardKey.KEY_Q);
            Raylib.InitAudioDevice();

            this._target = Raylib.LoadRenderTexture(MoonVars.RenderWidth, MoonVars.RenderHeight);
            this._scene  = new LogoScene(this);
        }
예제 #18
0
            private void Initialize()
            {
                if (_shadowRt != null)
                {
                    _shadowRt.Dispose();
                }
                var bb     = GraphicDeviceFactory.Device.BackBuffer;
                var kernel = EngineState.Shadow.ShadowMapping.PcfBlurSize;

                _shadowRt = new RenderTexture2D(bb.Width, bb.Height, Format.R8G8B8A8_UNORM);
                _vp       = new ViewPort(0, 0, _shadowRt.Width, _shadowRt.Height);
            }
 public void CommitChanges()
 {
     if (size != ShadowMap.Width)
     {
         if (ShadowMap != null)
         {
             ShadowMap.Dispose();
         }
         ShadowMap = new RenderTexture2D(size, size, Format.R32_FLOAT, Format.D16_UNORM);
         Rendered  = false;
     }
 }
예제 #20
0
        public DecalGlyp(Igneel.Rectangle screenRectangle)
        {
            IsDesignOnly  = true;
            IsTransparent = false;
            decal         = screenRectangle;

            renderTarget = new RenderTexture2D(decal.Width, decal.Height, Format.R8G8B8A8_UNORM_SRGB, Format.D24_UNORM_S8_UINT);
            hitTester    = new DecalGlypHitTest(decal.Width, decal.Height, Format.D24_UNORM_S8_UINT, this);

            components = new GlypComponent[0];

            SetupRender();
        }
    private void Correct(RenderTexture2D curNeedCorrectTex, RenderTexture2D errorTex)
    {
        int MGCorrectKernel = mComputeCorrect.FindKernel("MGCorrect");
        int WIDTH           = curNeedCorrectTex.Width;
        int HEIGHT          = curNeedCorrectTex.Height;

        mComputeCorrect.SetInt("_currentXSize", WIDTH);
        mComputeCorrect.SetInt("_currentYSize", HEIGHT);

        mComputeCorrect.SetTexture(MGCorrectKernel, "gNeedCorrectTex", curNeedCorrectTex.Source);
        mComputeCorrect.SetTexture(MGCorrectKernel, "gErrorTex", errorTex.Source);
        mComputeCorrect.Dispatch(MGCorrectKernel, Mathf.CeilToInt(WIDTH * 1.0f / mGroupThreadSizeX), Mathf.CeilToInt(HEIGHT * 1.0f / mGroupThreadSizeX), 1);
    }
예제 #22
0
 public RenderPipelineContext()
 {
     _bigBufferHandle = GCHandle.Alloc(bigBuffer);
     for (int i = 0; i < ScreenSizeRenderTextures.Length; i++)
     {
         ScreenSizeRenderTextures[i] = new RenderTexture2D();
     }
     for (int i = 0; i < ScreenSizeDSVs.Length; i++)
     {
         ScreenSizeDSVs[i] = new RenderTexture2D();
     }
     MaterialBufferGroup.Reload(768, 768 * 84);
 }
예제 #23
0
        public void Draw(RenderTexture2D target)
        {
            Raylib.BeginDrawing();
            {
                Raylib.BeginTextureMode(target);

                Raylib.ClearBackground(new Color(36, 36, 36, 255));

                Raylib.BeginMode2D(_camera);

                DrawGlobal();

                switch (GameState.CurrentPhase)
                {
                case EGamePhase.InitialPlacement:
                    DrawInitialPlacementCamera();
                    break;

                case EGamePhase.Expanding:
                    DrawConnections();
                    DrawExpandingCamera();
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                Raylib.EndMode2D();

                DrawGlobalUi();

                switch (GameState.CurrentPhase)
                {
                case EGamePhase.InitialPlacement:
                    DrawInitialPlacementUi();
                    break;

                case EGamePhase.Expanding:
                    DrawExpandingUi();
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                Raylib.EndTextureMode();
            }

            Raylib.EndDrawing();
        }
    private void Prologation(int destLevel, RenderTexture2D sourceHalfTex, RenderTexture2D destFullTex)
    {
        int MGProlongationKernel = mComputePrologation.FindKernel("MGProlongation");
        int WIDTH  = destFullTex.Width;
        int HEIGHT = destFullTex.Height;

        mComputePrologation.SetInt("_currentXSize", WIDTH);
        mComputePrologation.SetInt("_currentYSize", HEIGHT);

        mComputePrologation.SetTexture(MGProlongationKernel, "gSourceHalfTex", sourceHalfTex.Source);
        mComputePrologation.SetTexture(MGProlongationKernel, "gDestinationFullTex", destFullTex.Source);
        mComputePrologation.SetTexture(MGProlongationKernel, "gGridMarker", mCellMakerArray[destLevel].Source);
        mComputePrologation.Dispatch(MGProlongationKernel, Mathf.CeilToInt(WIDTH * 1.0f / mGroupThreadSizeX), Mathf.CeilToInt(HEIGHT * 1.0f / mGroupThreadSizeX), 1);
    }
예제 #25
0
    public void InitResource(int _width, int _height, float density, float numSimulateFPS = 10)
    {
        mWidth     = _width;
        mHeight    = _height;
        mGridSize  = 1.0f;//1.0f / Mathf.Min(mWidth, mHeight);
        mLevelSet  = new RenderTexture2D[2];
        mVelocityU = new RenderTexture2D[2];
        mVelocityV = new RenderTexture2D[2];

        mLevelSet[READ]   = new RenderTexture2D(mWidth, mHeight, "levelset0");
        mLevelSet[WRITE]  = new RenderTexture2D(mWidth, mHeight, "levelset1");
        mVelocityU[READ]  = new RenderTexture2D(mWidth + 1, mHeight, "velocityU0");
        mVelocityU[WRITE] = new RenderTexture2D(mWidth + 1, mHeight, "velocityU1");
        mVelocityV[READ]  = new RenderTexture2D(mWidth, mHeight + 1, "velocityV0");
        mVelocityV[WRITE] = new RenderTexture2D(mWidth, mHeight + 1, "velocityV1");

        mDivergence    = new RenderTexture2D(mWidth, mHeight, "divergence");
        mPressure      = new RenderTexture2D(mWidth, mHeight, "pressure0");
        mPressureWrite = new RenderTexture2D(mWidth, mHeight, "pressure1");

        mPoisson0 = new RenderTexture2D(mWidth, mHeight, "poisson0");
        mPoisson1 = new RenderTexture2D(mWidth, mHeight, "poisson1");
        mPoisson2 = new RenderTexture2D(mWidth, mHeight, "poisson2");

        mGridMarker = new RenderTexture2D(mWidth, mHeight, "gridMarker", RenderTextureFormat.RInt);
        mGridValidU = new RenderTexture2D[2];
        mGridValidV = new RenderTexture2D[2];

        mGridValidU[READ]  = new RenderTexture2D(mWidth + 1, mHeight, "gridValidU0", RenderTextureFormat.RInt);
        mGridValidU[WRITE] = new RenderTexture2D(mWidth + 1, mHeight, "gridValidU1", RenderTextureFormat.RInt);
        mGridValidV[READ]  = new RenderTexture2D(mWidth, mHeight + 1, "gridValidV0", RenderTextureFormat.RInt);
        mGridValidV[WRITE] = new RenderTexture2D(mWidth, mHeight + 1, "gridValidV1", RenderTextureFormat.RInt);

        currentTime         = System.DateTime.Now;
        simulateStepSeconds = 1.0f / numSimulateFPS;

        // init fast sweep
        mFsmConfig = new int[4, 4]
        {
            { 1, mWidth, 1, mHeight },
            { mWidth - 2, -1, 1, mHeight },
            { 1, mWidth, mHeight - 2, -1 },
            { mWidth - 2, -1, mHeight - 2, -1 },
        };

        // init start states
        InitFluidStartStage();
    }
예제 #26
0
        public void Resize(int width, int height, int scale)
        {
            screenWidth            = width;
            screenHeight           = height;
            windowWidth            = width * scale;
            windowHeight           = height * scale;
            ScreenController.scale = scale;
            Raylib.SetWindowSize(width * scale, height * scale);

            SoftwareCanvas.InitTexture(width, height);

            Raylib.UnloadRenderTexture(renderTexture);
            renderTexture = Util.LoadRenderTexture(screenWidth, screenHeight);
            drawScreen    = new SoftwareCanvasRenderer(Assets.Shader("shaders/screen"));
            ReloadShader();
        }
예제 #27
0
        public void Resize(int width, int height)
        {
            if (this._width == width && this._height == height)
            {
                return;
            }
            this._width  = width;
            this._height = height;

            if (_rtx != null)
            {
                _rtx.Dispose();
            }

            _rtx = new RenderTexture2D(_width, _height, Format.R8G8B8A8_UNORM, _depthFormat, Multisampling.Disable, true);
            _vp  = new ViewPort(0, 0, _width, _height);
        }
예제 #28
0
        /// <summary>
        /// Creates a new scene axes GUI.
        /// </summary>
        /// <param name="window">Window in which the GUI is located in.</param>
        /// <param name="panel">Panel onto which to place the GUI element.</param>
        /// <param name="width">Width of the GUI element.</param>
        /// <param name="height">Height of the GUI element.</param>
        /// <param name="projType">Projection type to display on the GUI.</param>
        public SceneAxesGUI(SceneWindow window, GUIPanel panel, int width, int height, ProjectionType projType)
        {
            renderTexture          = new RenderTexture2D(PixelFormat.R8G8B8A8, width, height);
            renderTexture.Priority = 1;

            SceneObject cameraSO = new SceneObject("SceneAxesCamera", true);

            camera              = cameraSO.AddComponent <Camera>();
            camera.Target       = renderTexture;
            camera.ViewportRect = new Rect2(0.0f, 0.0f, 1.0f, 1.0f);

            cameraSO.Position = new Vector3(0, 0, 5);
            cameraSO.LookAt(new Vector3(0, 0, 0));

            camera.Priority       = 2;
            camera.NearClipPlane  = 0.05f;
            camera.FarClipPlane   = 1000.0f;
            camera.ClearColor     = new Color(0.0f, 0.0f, 0.0f, 0.0f);
            camera.ProjectionType = ProjectionType.Orthographic;
            camera.Layers         = SceneAxesHandle.LAYER;
            camera.AspectRatio    = 1.0f;
            camera.OrthoHeight    = 2.0f;
            camera.HDR            = false;

            renderTextureGUI = new GUIRenderTexture(renderTexture, true);

            GUILayoutY layout        = panel.AddLayoutY();
            GUILayoutX textureLayout = layout.AddLayoutX();

            textureLayout.AddElement(renderTextureGUI);
            textureLayout.AddFlexibleSpace();

            Rect2I bounds = new Rect2I(0, 0, width, height);

            sceneHandles            = new SceneHandles(window, camera);
            renderTextureGUI.Bounds = bounds;

            labelGUI = new GUILabel(projType.ToString(), EditorStyles.LabelCentered);
            layout.AddElement(labelGUI);
            layout.AddFlexibleSpace();

            this.panel  = panel;
            this.bounds = bounds;
        }
예제 #29
0
        /// <summary>
        /// Creates or rebuilds the main render texture. Should be called at least once before using the
        /// game window. Should be called whenever the window is resized.
        /// </summary>
        /// <param name="width">Width of the scene render target, in pixels.</param>
        /// <param name="height">Height of the scene render target, in pixels.</param>
        private void UpdateRenderTexture(int width, int height)
        {
            height = height - HeaderHeight;

            int rtWidth  = MathEx.Max(20, width);
            int rtHeight = MathEx.Max(20, height);

            if (selectedAspectRatio != 0) // 0 is free aspect
            {
                AspectRatio aspectRatio = aspectRatios[selectedAspectRatio - 1];

                int visibleAreaHeight = rtHeight;

                float aspectInv = aspectRatio.height / (float)aspectRatio.width;
                rtHeight = MathEx.RoundToInt(rtWidth * aspectInv);

                if (rtHeight > visibleAreaHeight)
                {
                    rtHeight = visibleAreaHeight;
                    float aspect = aspectRatio.width / (float)aspectRatio.height;
                    rtWidth = MathEx.RoundToInt(rtHeight * aspect);
                }
            }

            RenderTexture2D renderTexture = new RenderTexture2D(PixelFormat.R8G8B8A8, rtWidth, rtHeight)
            {
                Priority = 1
            };

            EditorApplication.MainRenderTarget = renderTexture;
            renderTextureGUI.RenderTexture     = renderTexture;

            int offsetX = (width - rtWidth) / 2;
            int offsetY = (height - rtHeight) / 2;

            Rect2I rtBounds = new Rect2I(offsetX, offsetY, rtWidth, rtHeight);

            renderTextureGUI.Bounds = rtBounds;

            Rect2I bgBounds = new Rect2I(0, 0, width, height);

            renderTextureBg.Bounds = bgBounds;
        }
예제 #30
0
        private int CreateResources()
        {
            GraphicDevice device     = GraphicDeviceFactory.Device;
            var           backBuffer = device.BackBuffer;
            int           width      = backBuffer.Width;
            int           height     = backBuffer.Height;

            Format depthFormat = Format.UNKNOWN;

            _rtHdrScene                = new RenderTexture2D(width, height, _hdrFormat, device.BackDepthBuffer.SurfaceFormat, backBuffer.Sampling);
            _rtBrightPassFilter        = new RenderTexture2D(width / 2, height / 2, Format.R8G8B8A8_UNORM, depthFormat);
            _rtStartSource             = new RenderTexture2D(width / 4, height / 4, Format.R8G8B8A8_UNORM, depthFormat);
            _rtCurrentAdaptedLuminance = new RenderTexture2D(1, 1, _luminanceFormat, depthFormat);
            _rtLastAdaptedLuminance    = new RenderTexture2D(1, 1, _luminanceFormat, depthFormat);
            _rtStarFinal               = new RenderTexture2D(_rtStartSource.Width, _rtStartSource.Height, Format.R8G8B8A8_UNORM, depthFormat);

            int i;

            for (i = 0; i < Bloomtextures; i++)
            {
                _rtBloom[i] = new RenderTexture2D(width / 8, height / 8, Format.R8G8B8A8_UNORM);
            }

            for (i = 0; i < Starmaxlines; i++)
            {
                _rtStarLines[i] = new RenderTexture2D(_rtStartSource.Width, _rtStartSource.Height, _hdrFormat);
            }

            for (i = 0; i < Starmaxpasses; i++)
            {
                _rtStarPasses[i] = new RenderTexture2D(_rtStartSource.Width, _rtStartSource.Height, _hdrFormat);
            }

            int size = 1;

            for (i = 0; i < Tonemaptextures; i++)
            {
                _rtToneMap[i] = new RenderTexture2D(size, size, _luminanceFormat, depthFormat);
                size         *= 3;
            }
            return(i);
        }