Esempio n. 1
0
        public void Draw(Camera camera, bool flip, float epsilon, float normalDelta)
        {
            if (_disposing)
            {
                return;
            }
            if (camera == null)
            {
                return;
            }
            if (_data == null)
            {
                return;
            }
            if (_props == null)
            {
                return;
            }
            if (_cmd == null)
            {
                return;
            }
            if (_material == null)
            {
                return;
            }

            _data.SetMaterialProperties(_props);

            if (debugTex3D != null)
            {
                _props.SetTexture("_SDFVolumeTex", debugTex3D);
            }

            _props.SetMatrix(_SDFVolumeLocalToWorld, _volume.LocalToWorldNoScale);
            _props.SetMatrix(_SDFVolumeWorldToLocal, _volume.LocalToWorldNoScale.inverse);
            _props.SetFloat(_SDFVolumeFlip, flip ? -1f : 1f);
            _props.SetVector(_BlitScaleBiasRt, new Vector4(1f, 1f, 0f, 0f));
            _props.SetVector(_BlitScaleBias, new Vector4(1f, 1f, 0f, 0f));
            _props.SetFloat(_SDFPreviewEpsilon, epsilon);
            _props.SetFloat(_SDFPreviewNormalDelta, normalDelta);

            AVolumeUtils.SetupRaymarchingMatrix(
                camera.fieldOfView,
                camera.worldToCameraMatrix,
                new Vector2(camera.pixelWidth, camera.pixelHeight));

            _cmd.Clear();
            _cmd.DrawProcedural(Matrix4x4.identity, _material, 0, MeshTopology.Quads, 4, 1, _props);
            Graphics.ExecuteCommandBuffer(_cmd);
        }
Esempio n. 2
0
        public void Draw(Camera camera, bool flip, float epsilon, float normalDelta, bool rayDirVertexShader = false)
        {
            if (_disposing)
            {
                return;
            }
            if (camera == null)
            {
                return;
            }
            if (_data == null)
            {
                return;
            }
            if (_props == null)
            {
                return;
            }
            if (_cmd == null)
            {
                return;
            }
            if (_material == null)
            {
                return;
            }

            _data.SetMaterialProperties(_props);

            if (debugTex3D != null)
            {
                _props.SetTexture("_SDFVolumeTex", debugTex3D);
            }

            _props.SetMatrix(_SDFVolumeLocalToWorld, LocalToWorldNoScale);
            _props.SetMatrix(_SDFVolumeWorldToLocal, LocalToWorldNoScale.inverse);
            _props.SetFloat(_SDFVolumeFlip, flip ? -1f : 1f);
            _props.SetFloat(_SDFPreviewEpsilon, epsilon);
            _props.SetFloat(_SDFPreviewNormalDelta, normalDelta);

            // These are connstant - add to different CBUFFER?
            _props.SetVector(_BlitScaleBiasRt, new Vector4(1f, 1f, 0f, 0f));
            _props.SetVector(_BlitScaleBias, new Vector4(1f, 1f, 0f, 0f));

            if (rayDirVertexShader)
            {
                // Using procedural quad generation with rayDir calcaultion in vertex shader.
                AVolumeUtils.ClearRaymarchingMatrix();                 // just for debugging
                // Not an actual matrix, just using matrix as convient storage type.
                _props.SetMatrix(_FrustumWorldCorners, AVolumeUtils.GetCameraFrustumWorldCorners(camera));
            }
            else
            {
                AVolumeUtils.SetupRaymarchingMatrix(camera.fieldOfView, camera.worldToCameraMatrix, new Vector2(camera.pixelWidth, camera.pixelHeight));
            }

            _cmd.Clear();
            _cmd.DrawProcedural(Matrix4x4.identity, _material, 0, MeshTopology.Quads, 4, 1, _props);
            Graphics.ExecuteCommandBuffer(_cmd);

            // Debug.Log( $"rayDirVertexShader: {rayDirVertexShader} _material: {_material.shader.name}");
        }