/// <summary> /// スカラーで除算する。 /// </summary> /// <param name="v1">値1</param> /// <param name="v2">値2</param> /// <returns>v1/v2</returns> public static Vector2DI DivideByScalar(Vector2DI v1, float v2) { var ret = new Vector2DI(); ret.X = (int)(v1.X / v2); ret.Y = (int)(v1.Y / v2); return(ret); }
private static Vector2DF GetPosition(Vector2DI size, CenterPosition centerPosition) { switch(centerPosition) { case CenterPosition.TopLeft: return new Vector2DF(0, 0); case CenterPosition.TopCenter: return new Vector2DF((float)size.X / 2, 0); case CenterPosition.TopRight: return new Vector2DF(size.X, 0); case CenterPosition.CenterLeft: return new Vector2DF(0, (float)size.Y / 2); case CenterPosition.CenterCenter: return new Vector2DF((float)size.X / 2, (float)size.Y / 2); case CenterPosition.CenterRight: return new Vector2DF(size.X, (float)size.Y / 2); case CenterPosition.BottomLeft: return new Vector2DF(0, size.Y); case CenterPosition.BottomCenter: return new Vector2DF((float)size.X / 2, size.Y); case CenterPosition.BottomRight: return new Vector2DF(size.X, size.Y); default: throw new Exception(); } }
/// <summary> /// コンストラクタ /// </summary> /// <param name="position">左上座標</param> /// <param name="size">大きさ</param> public RectI(Vector2DI position, Vector2DI size) : this(position.X, position.Y, size.X, size.Y) { }
public bool Equals(Vector2DI other) { return(X == other.X && Y == other.Y); }
/// <summary> /// マウスカーソルを作成する。 /// </summary> /// <param name="path">画像のパス</param> /// <param name="hot">カーソルの相対座標</param> /// <returns>カーソル</returns> public static Cursor CreateCursor(string path, Vector2DI hot) { return(GC.GenerateCursor(core.CreateCursor(path, hot), GenerationType.Create)); }
protected 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.Equals(Vector2DI.DivideByScalar(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(0.5f / (float)(size.X / 1.0f), 0.5f / (float)(size.Y / 1.0f))); DrawOnTexture2DWithMaterial(downsampledTexture0, downsample); downsample.SetTexture2D("g_texture", downsampledTexture0); downsample.SetTextureFilterType("g_texture", TextureFilterType.Linear); downsample.SetVector2DF("g_offset", new Vector2DF(0.5f / (float)(size.X / 2.0f), 0.5f / (float)(size.Y / 2.0f))); DrawOnTexture2DWithMaterial(downsampledTexture1, downsample); downsample.SetTexture2D("g_texture", downsampledTexture1); downsample.SetTextureFilterType("g_texture", TextureFilterType.Linear); downsample.SetVector2DF("g_offset", new Vector2DF(0.5f / (float)(size.X / 4.0f), 0.5f / (float)(size.Y / 4.0f))); DrawOnTexture2DWithMaterial(downsampledTexture2, downsample); downsample.SetTexture2D("g_texture", downsampledTexture2); downsample.SetTextureFilterType("g_texture", TextureFilterType.Linear); downsample.SetVector2DF("g_offset", new Vector2DF(0.5f / (float)(size.X / 8.0f), 0.5f / (float)(size.Y / 8.0f))); 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); }
public static RectI WithPosition(this RectI source, Vector2DI position) { return new RectI(position.X, position.Y, source.Width, source.Height); }
public static RectI Shift(this RectI source, Vector2DI shift) { return new RectI(source.X + shift.X, source.Y + shift.Y, source.Width, source.Height); }