Exemple #1
0
        /// <summary>
        /// 2点間の距離を取得する。
        /// </summary>
        /// <param name="v1">v1ベクトル</param>
        /// <param name="v2">v2ベクトル</param>
        /// <returns>v1とv2の距離</returns>
        public static float Distance(Vector4DF v1, Vector4DF v2)
        {
            float dx = v1.X - v2.X;
            float dy = v1.Y - v2.Y;
            float dz = v1.Z - v2.Z;
            float dw = v1.W - v2.W;

            return((float)Math.Sqrt(dx * dx + dy * dy + dz * dz + dw * dw));
        }
Exemple #2
0
        /// <summary>
        /// 行列でベクトルを変形させる。
        /// </summary>
        /// <param name="in_">変形前ベクトル</param>
        /// <returns>変形後ベクトル</returns>
        public Vector4DF Transform4D(Vector4DF in_)
        {
            float *values = stackalloc float[4];

            fixed(float *v = Values)
            {
                for (int i = 0; i < 4; i++)
                {
                    values[i]  = 0;
                    values[i] += in_.X * v[i * 4 + 0];
                    values[i] += in_.Y * v[i * 4 + 1];
                    values[i] += in_.Z * v[i * 4 + 2];
                    values[i] += in_.W * v[i * 4 + 3];
                }
            }

            Vector4DF o = new Vector4DF();

            o.X = values[0];
            o.Y = values[1];
            o.Z = values[2];
            o.W = values[3];
            return(o);
        }
 public void SetVector4DF(string name, Vector4DF value)
 {
     CoreInstance.SetVector4DF(name, value);
 }
Exemple #4
0
        public override void OnDraw(RenderTexture2D dst, RenderTexture2D src)
        {
            Vector4DF weights1 = new Vector4DF();
            Vector4DF weights2 = new Vector4DF();

            float[] ws         = new float[8];
            float   total      = 0.0f;
            float   dispersion = intensity * intensity;

            for (int i = 0; i < 8; i++)
            {
                float pos = 1.0f + 2.0f * i;
                ws[i]  = (float)Math.Exp(-0.5f * pos * pos / dispersion);
                total += ws[i] * 2.0f;
            }
            weights1.X = ws[0] / total;
            weights1.Y = ws[1] / total;
            weights1.Z = ws[2] / total;
            weights1.W = ws[3] / total;
            weights2.X = ws[4] / total;
            weights2.Y = ws[5] / total;
            weights2.Z = ws[6] / total;
            weights2.W = ws[7] / total;

            var size   = src.Size;
            var format = src.Format;

            if (tempTexture0 == null ||
                (tempTexture0.Size != size / 2 || tempTexture0.Format != format))
            {
                if (format == TextureFormat.R32G32B32A32_FLOAT)
                {
                    tempTexture0 = Engine.Graphics.CreateRenderTexture2D(size.X / 2, size.Y / 2, TextureFormat.R32G32B32A32_FLOAT);
                    tempTexture1 = Engine.Graphics.CreateRenderTexture2D(size.X / 4, size.Y / 4, TextureFormat.R32G32B32A32_FLOAT);
                    tempTexture2 = Engine.Graphics.CreateRenderTexture2D(size.X / 8, size.Y / 8, TextureFormat.R32G32B32A32_FLOAT);
                    tempTexture3 = Engine.Graphics.CreateRenderTexture2D(size.X / 16, size.Y / 16, TextureFormat.R32G32B32A32_FLOAT);

                    downsampledTexture0 = Engine.Graphics.CreateRenderTexture2D(size.X / 2, size.Y / 2, TextureFormat.R32G32B32A32_FLOAT);
                    downsampledTexture1 = Engine.Graphics.CreateRenderTexture2D(size.X / 4, size.Y / 4, TextureFormat.R32G32B32A32_FLOAT);
                    downsampledTexture2 = Engine.Graphics.CreateRenderTexture2D(size.X / 8, size.Y / 8, TextureFormat.R32G32B32A32_FLOAT);
                    downsampledTexture3 = Engine.Graphics.CreateRenderTexture2D(size.X / 16, size.Y / 16, TextureFormat.R32G32B32A32_FLOAT);
                }
                else
                {
                    tempTexture0 = Engine.Graphics.CreateRenderTexture2D(size.X / 2, size.Y / 2, TextureFormat.R8G8B8A8_UNORM);
                    tempTexture1 = Engine.Graphics.CreateRenderTexture2D(size.X / 4, size.Y / 4, TextureFormat.R8G8B8A8_UNORM);
                    tempTexture2 = Engine.Graphics.CreateRenderTexture2D(size.X / 8, size.Y / 8, TextureFormat.R8G8B8A8_UNORM);
                    tempTexture3 = Engine.Graphics.CreateRenderTexture2D(size.X / 16, size.Y / 16, TextureFormat.R8G8B8A8_UNORM);

                    downsampledTexture0 = Engine.Graphics.CreateRenderTexture2D(size.X / 2, size.Y / 2, TextureFormat.R8G8B8A8_UNORM);
                    downsampledTexture1 = Engine.Graphics.CreateRenderTexture2D(size.X / 4, size.Y / 4, TextureFormat.R8G8B8A8_UNORM);
                    downsampledTexture2 = Engine.Graphics.CreateRenderTexture2D(size.X / 8, size.Y / 8, TextureFormat.R8G8B8A8_UNORM);
                    downsampledTexture3 = Engine.Graphics.CreateRenderTexture2D(size.X / 16, size.Y / 16, TextureFormat.R8G8B8A8_UNORM);
                }
            }

            downsample.SetTexture2D("g_texture", src);
            downsample.SetTextureFilterType("g_texture", TextureFilterType.Linear);
            downsample.SetVector2DF("g_offset", new Vector2DF(1.0f / (float)size.X, 1.0f / (float)size.Y));
            DrawOnTexture2DWithMaterial(downsampledTexture0, downsample);

            downsample.SetTexture2D("g_texture", downsampledTexture0);
            downsample.SetTextureFilterType("g_texture", TextureFilterType.Linear);
            downsample.SetVector2DF("g_offset", new Vector2DF(2.0f / (float)size.X, 2.0f / (float)size.Y));
            DrawOnTexture2DWithMaterial(downsampledTexture1, downsample);

            downsample.SetTexture2D("g_texture", downsampledTexture1);
            downsample.SetTextureFilterType("g_texture", TextureFilterType.Linear);
            downsample.SetVector2DF("g_offset", new Vector2DF(4.0f / (float)size.X, 4.0f / (float)size.Y));
            DrawOnTexture2DWithMaterial(downsampledTexture2, downsample);

            downsample.SetTexture2D("g_texture", downsampledTexture2);
            downsample.SetTextureFilterType("g_texture", TextureFilterType.Linear);
            downsample.SetVector2DF("g_offset", new Vector2DF(8.0f / (float)size.X, 8.0f / (float)size.Y));
            DrawOnTexture2DWithMaterial(downsampledTexture3, downsample);

            Material2D blurX = null;

            if (isLuminanceMode)
            {
                blurX = material2dX_Lum;
            }
            else
            {
                blurX = material2dX;
            }

            // ブラー1
            blurX.SetTexture2D("g_blurredTexture", downsampledTexture1);
            blurX.SetVector4DF("g_weight1", weights1);
            blurX.SetVector4DF("g_weight2", weights2);
            blurX.SetFloat("g_threshold", threshold);
            blurX.SetFloat("g_exposure", exposure);
            blurX.SetTextureFilterType("g_blurredTexture", TextureFilterType.Linear);
            DrawOnTexture2DWithMaterial(tempTexture1, blurX);

            material2dY.SetTexture2D("g_blurredTexture", tempTexture1);
            material2dY.SetVector4DF("g_weight1", weights1);
            material2dY.SetVector4DF("g_weight2", weights2);
            material2dY.SetTextureFilterType("g_blurredTexture", TextureFilterType.Linear);
            DrawOnTexture2DWithMaterial(downsampledTexture1, material2dY);

            // ブラー2
            blurX.SetTexture2D("g_blurredTexture", downsampledTexture2);
            blurX.SetVector4DF("g_weight1", weights1);
            blurX.SetVector4DF("g_weight2", weights2);
            blurX.SetFloat("g_threshold", threshold);
            blurX.SetFloat("g_exposure", exposure);
            blurX.SetTextureFilterType("g_blurredTexture", TextureFilterType.Linear);
            DrawOnTexture2DWithMaterial(tempTexture2, blurX);

            material2dY.SetTexture2D("g_blurredTexture", tempTexture2);
            material2dY.SetVector4DF("g_weight1", weights1);
            material2dY.SetVector4DF("g_weight2", weights2);
            material2dY.SetTextureFilterType("g_blurredTexture", TextureFilterType.Linear);
            DrawOnTexture2DWithMaterial(downsampledTexture2, material2dY);

            // ブラー3
            blurX.SetTexture2D("g_blurredTexture", downsampledTexture3);
            blurX.SetVector4DF("g_weight1", weights1);
            blurX.SetVector4DF("g_weight2", weights2);
            blurX.SetFloat("g_threshold", threshold);
            blurX.SetFloat("g_exposure", exposure);
            blurX.SetTextureFilterType("g_blurredTexture", TextureFilterType.Linear);
            DrawOnTexture2DWithMaterial(tempTexture3, blurX);

            material2dY.SetTexture2D("g_blurredTexture", tempTexture3);
            material2dY.SetVector4DF("g_weight1", weights1);
            material2dY.SetVector4DF("g_weight2", weights2);
            material2dY.SetTextureFilterType("g_blurredTexture", TextureFilterType.Linear);
            DrawOnTexture2DWithMaterial(downsampledTexture3, material2dY);

            // 合計
            materialSum.SetTexture2D("g_blurred0Texture", downsampledTexture1);
            materialSum.SetTexture2D("g_blurred1Texture", downsampledTexture2);
            materialSum.SetTexture2D("g_blurred2Texture", downsampledTexture3);
            materialSum.SetTexture2D("g_originalTexture", src);
            materialSum.SetTextureFilterType("g_blurred0Texture", TextureFilterType.Linear);
            materialSum.SetTextureFilterType("g_blurred1Texture", TextureFilterType.Linear);
            materialSum.SetTextureFilterType("g_blurred2Texture", TextureFilterType.Linear);
            materialSum.SetTextureFilterType("g_originalTexture", TextureFilterType.Linear);

            DrawOnTexture2DWithMaterial(dst, materialSum);
        }
Exemple #5
0
 /// <summary>
 /// 外積を取得する。
 /// </summary>
 /// <param name="v1">v1ベクトル</param>
 /// <param name="v2">v2ベクトル</param>
 /// <returns>外積v1×v2</returns>
 public static float Dot(Vector4DF v1, Vector4DF v2)
 {
     return v1.X * v2.X + v1.Y * v2.Y + v1.Z * v2.Z + v1.W * v2.W;
 }
Exemple #6
0
 /// <summary>
 /// 2点間の距離を取得する。
 /// </summary>
 /// <param name="v1">v1ベクトル</param>
 /// <param name="v2">v2ベクトル</param>
 /// <returns>v1とv2の距離</returns>
 public static float Distance(Vector4DF v1, Vector4DF v2)
 {
     float dx = v1.X - v2.X;
     float dy = v1.Y - v2.Y;
     float dz = v1.Z - v2.Z;
     float dw = v1.W - v2.W;
     return (float)Math.Sqrt(dx * dx + dy * dy + dz * dz + dw * dw);
 }
        public override void OnDraw(RenderTexture2D dst, RenderTexture2D src)
        {
            Vector4DF weights1 = new Vector4DF();
            Vector4DF weights2 = new Vector4DF();

            float[] ws = new float[8];
            float total = 0.0f;
            float dispersion = intensity * intensity;
            for (int i = 0; i < 8; i++)
            {
                float pos = 1.0f + 2.0f * i;
                ws[i] = (float)Math.Exp(-0.5f * pos * pos / dispersion);
                total += ws[i] * 2.0f;
            }
            weights1.X = ws[0] / total;
            weights1.Y = ws[1] / total;
            weights1.Z = ws[2] / total;
            weights1.W = ws[3] / total;
            weights2.X = ws[4] / total;
            weights2.Y = ws[5] / total;
            weights2.Z = ws[6] / total;
            weights2.W = ws[7] / total;

            var size = src.Size;
            var format = src.Format;

            if (tempTexture0 == null ||
                (tempTexture0.Size != size / 2 || tempTexture0.Format != format))
            {
                if (format == TextureFormat.R32G32B32A32_FLOAT)
                {
                    tempTexture0 = Engine.Graphics.CreateRenderTexture2D(size.X / 2, size.Y / 2, TextureFormat.R32G32B32A32_FLOAT);
                    tempTexture1 = Engine.Graphics.CreateRenderTexture2D(size.X / 4, size.Y / 4, TextureFormat.R32G32B32A32_FLOAT);
                    tempTexture2 = Engine.Graphics.CreateRenderTexture2D(size.X / 8, size.Y / 8, TextureFormat.R32G32B32A32_FLOAT);
                    tempTexture3 = Engine.Graphics.CreateRenderTexture2D(size.X / 16, size.Y / 16, TextureFormat.R32G32B32A32_FLOAT);

                    downsampledTexture0 = Engine.Graphics.CreateRenderTexture2D(size.X / 2, size.Y / 2, TextureFormat.R32G32B32A32_FLOAT);
                    downsampledTexture1 = Engine.Graphics.CreateRenderTexture2D(size.X / 4, size.Y / 4, TextureFormat.R32G32B32A32_FLOAT);
                    downsampledTexture2 = Engine.Graphics.CreateRenderTexture2D(size.X / 8, size.Y / 8, TextureFormat.R32G32B32A32_FLOAT);
                    downsampledTexture3 = Engine.Graphics.CreateRenderTexture2D(size.X / 16, size.Y / 16, TextureFormat.R32G32B32A32_FLOAT);
                }
                else
                {
                    tempTexture0 = Engine.Graphics.CreateRenderTexture2D(size.X / 2, size.Y / 2, TextureFormat.R8G8B8A8_UNORM);
                    tempTexture1 = Engine.Graphics.CreateRenderTexture2D(size.X / 4, size.Y / 4, TextureFormat.R8G8B8A8_UNORM);
                    tempTexture2 = Engine.Graphics.CreateRenderTexture2D(size.X / 8, size.Y / 8, TextureFormat.R8G8B8A8_UNORM);
                    tempTexture3 = Engine.Graphics.CreateRenderTexture2D(size.X / 16, size.Y / 16, TextureFormat.R8G8B8A8_UNORM);

                    downsampledTexture0 = Engine.Graphics.CreateRenderTexture2D(size.X / 2, size.Y / 2, TextureFormat.R8G8B8A8_UNORM);
                    downsampledTexture1 = Engine.Graphics.CreateRenderTexture2D(size.X / 4, size.Y / 4, TextureFormat.R8G8B8A8_UNORM);
                    downsampledTexture2 = Engine.Graphics.CreateRenderTexture2D(size.X / 8, size.Y / 8, TextureFormat.R8G8B8A8_UNORM);
                    downsampledTexture3 = Engine.Graphics.CreateRenderTexture2D(size.X / 16, size.Y / 16, TextureFormat.R8G8B8A8_UNORM);
                }
            }

            downsample.SetTexture2D("g_texture", src);
            downsample.SetTextureFilterType("g_texture", TextureFilterType.Linear);
            downsample.SetVector2DF("g_offset", new Vector2DF(1.0f / (float)size.X, 1.0f / (float)size.Y));
            DrawOnTexture2DWithMaterial(downsampledTexture0, downsample);

            downsample.SetTexture2D("g_texture", downsampledTexture0);
            downsample.SetTextureFilterType("g_texture", TextureFilterType.Linear);
            downsample.SetVector2DF("g_offset", new Vector2DF(2.0f / (float)size.X, 2.0f / (float)size.Y));
            DrawOnTexture2DWithMaterial(downsampledTexture1, downsample);

            downsample.SetTexture2D("g_texture", downsampledTexture1);
            downsample.SetTextureFilterType("g_texture", TextureFilterType.Linear);
            downsample.SetVector2DF("g_offset", new Vector2DF(4.0f / (float)size.X, 4.0f / (float)size.Y));
            DrawOnTexture2DWithMaterial(downsampledTexture2, downsample);

            downsample.SetTexture2D("g_texture", downsampledTexture2);
            downsample.SetTextureFilterType("g_texture", TextureFilterType.Linear);
            downsample.SetVector2DF("g_offset", new Vector2DF(8.0f / (float)size.X, 8.0f / (float)size.Y));
            DrawOnTexture2DWithMaterial(downsampledTexture3, downsample);

            Material2D blurX = null;
            if (isLuminanceMode)
            {
                blurX = material2dX_Lum;
            }
            else
            {
                blurX = material2dX;
            }

            // ブラー1
            blurX.SetTexture2D("g_blurredTexture", downsampledTexture1);
            blurX.SetVector4DF("g_weight1", weights1);
            blurX.SetVector4DF("g_weight2", weights2);
            blurX.SetFloat("g_threshold", threshold);
            blurX.SetFloat("g_exposure", exposure);
            blurX.SetTextureFilterType("g_blurredTexture", TextureFilterType.Linear);
            DrawOnTexture2DWithMaterial(tempTexture1, blurX);

            material2dY.SetTexture2D("g_blurredTexture", tempTexture1);
            material2dY.SetVector4DF("g_weight1", weights1);
            material2dY.SetVector4DF("g_weight2", weights2);
            material2dY.SetTextureFilterType("g_blurredTexture", TextureFilterType.Linear);
            DrawOnTexture2DWithMaterial(downsampledTexture1, material2dY);

            // ブラー2
            blurX.SetTexture2D("g_blurredTexture", downsampledTexture2);
            blurX.SetVector4DF("g_weight1", weights1);
            blurX.SetVector4DF("g_weight2", weights2);
            blurX.SetFloat("g_threshold", threshold);
            blurX.SetFloat("g_exposure", exposure);
            blurX.SetTextureFilterType("g_blurredTexture", TextureFilterType.Linear);
            DrawOnTexture2DWithMaterial(tempTexture2, blurX);

            material2dY.SetTexture2D("g_blurredTexture", tempTexture2);
            material2dY.SetVector4DF("g_weight1", weights1);
            material2dY.SetVector4DF("g_weight2", weights2);
            material2dY.SetTextureFilterType("g_blurredTexture", TextureFilterType.Linear);
            DrawOnTexture2DWithMaterial(downsampledTexture2, material2dY);

            // ブラー3
            blurX.SetTexture2D("g_blurredTexture", downsampledTexture3);
            blurX.SetVector4DF("g_weight1", weights1);
            blurX.SetVector4DF("g_weight2", weights2);
            blurX.SetFloat("g_threshold", threshold);
            blurX.SetFloat("g_exposure", exposure);
            blurX.SetTextureFilterType("g_blurredTexture", TextureFilterType.Linear);
            DrawOnTexture2DWithMaterial(tempTexture3, blurX);

            material2dY.SetTexture2D("g_blurredTexture", tempTexture3);
            material2dY.SetVector4DF("g_weight1", weights1);
            material2dY.SetVector4DF("g_weight2", weights2);
            material2dY.SetTextureFilterType("g_blurredTexture", TextureFilterType.Linear);
            DrawOnTexture2DWithMaterial(downsampledTexture3, material2dY);

            // 合計
            materialSum.SetTexture2D("g_blurred0Texture", downsampledTexture1);
            materialSum.SetTexture2D("g_blurred1Texture", downsampledTexture2);
            materialSum.SetTexture2D("g_blurred2Texture", downsampledTexture3);
            materialSum.SetTexture2D("g_originalTexture", src);
            materialSum.SetTextureFilterType("g_blurred0Texture", TextureFilterType.Linear);
            materialSum.SetTextureFilterType("g_blurred1Texture", TextureFilterType.Linear);
            materialSum.SetTextureFilterType("g_blurred2Texture", TextureFilterType.Linear);
            materialSum.SetTextureFilterType("g_originalTexture", TextureFilterType.Linear);

            DrawOnTexture2DWithMaterial(dst, materialSum);
        }
Exemple #8
0
 /// <summary>
 /// 外積を取得する。
 /// </summary>
 /// <param name="v1">v1ベクトル</param>
 /// <param name="v2">v2ベクトル</param>
 /// <returns>外積v1×v2</returns>
 public static float Dot(Vector4DF v1, Vector4DF v2)
 {
     return(v1.X * v2.X + v1.Y * v2.Y + v1.Z * v2.Z + v1.W * v2.W);
 }
 public void SetVector4DF(string name, Vector4DF value)
 {
     SwigObject.SetVector4DF(name, value);
 }
Exemple #10
0
        /// <summary>
        /// 行列でベクトルを変形させる。
        /// </summary>
        /// <param name="in_">変形前ベクトル</param>
        /// <returns>変形後ベクトル</returns>
        public Vector4DF Transform4D(Vector4DF in_)
        {
            float* values = stackalloc float[4];

            fixed (float* v = Values)
            {
                for (int i = 0; i < 4; i++)
                {
                    values[i] = 0;
                    values[i] += in_.X * v[i * 4 + 0];
                    values[i] += in_.Y * v[i * 4 + 1];
                    values[i] += in_.Z * v[i * 4 + 2];
                    values[i] += in_.W * v[i * 4 + 3];
                }
            }

            Vector4DF o = new Vector4DF();
            o.X = values[0];
            o.Y = values[1];
            o.Z = values[2];
            o.W = values[3];
            return o;
        }
 public void SetVector4DF(string name, Vector4DF value)
 {
     SwigObject.SetVector4DF(name, value);
 }