public MainViewModel() { this.Title = "Environment Mapping Demo"; this.SubTitle = "HelixToolkitDX"; // camera setup this.Camera = new PerspectiveCamera { Position = new Point3D(10, 0, 0), LookDirection = new Vector3D(-10, 0, 0), UpDirection = new Vector3D(0, 1, 0) }; //this.Camera = new OrthographicCamera { Position = new Point3D(3, 3, 5), LookDirection = new Vector3D(-3, -3, -5), UpDirection = new Vector3D(0, 1, 0) }; // lighting setup this.AmbientLightColor = new Color4(0.5f, 0.5f, 0.5f, 1.0f); this.DirectionalLightColor = Color.White; this.DirectionalLightDirection = new Vector3(-2, -1, 1); // scene model3d var b1 = new MeshBuilder(true); b1.AddSphere(new Vector3(0, 0, 0), 1.0, 64, 64); b1.AddBox(new Vector3(0, 0, 0), 1, 0.5, 3, BoxFaces.All); this.Model = b1.ToMeshGeometry3D(); this.ModelTransform = new Media3D.TranslateTransform3D(); this.ModelMaterial = PhongMaterials.Copper; RenderTechniquesManager = new DefaultRenderTechniquesManager(); RenderTechnique = RenderTechniquesManager.RenderTechniques[DefaultRenderTechniqueNames.Blinn]; EffectsManager = new DefaultEffectsManager(RenderTechniquesManager); }
public Vertex(Vector4 position, Color4 color, Vector2 textureCoordinate, uint faceIndex) { Position = position; Color = color; TextureCoordinate = textureCoordinate; FaceIndex = faceIndex; }
/// <summary> /// Constructor for the Vertex3 class, takes float variables for the x y and z positions, as well as a color. /// </summary> /// <param name="x">The float representation of the Vertex3's x position.</param> /// <param name="y">The float representation of the Vertex3's y position.</param> /// <param name="z">The float representation of the Vertex3's z position.</param> /// <param name="color">The color of this particular Vertex3.</param> public Vertex3(float x, float y, float z, Color4 color) { this.x = x; this.y = y; this.z = z; this.myColor = color; }
public Disc(FundamentalRegion region, Bitmap bitmap, bool isInverting) { this.fundamentalRegion = region; this.isInverting = isInverting; currentFace = new Face(fundamentalRegion); // TBD fix extra face bug when centered initialFace = currentFace; // texture GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest); texture = CreateTexture(bitmap); int r = 0, g = 0, b = 0; int size = bitmap.Width * bitmap.Height; int skip = 16; size = 0; for (int i = 0; i < bitmap.Width; i += skip) { for (int j = 0; j < bitmap.Height; j += skip) { Color color = bitmap.GetPixel(i, j); r += color.R; g += color.G; b += color.B; size++; } } r /= size; g /= size; b /= size; backgroundColor = Color.FromArgb(r, g, b); drawCount = 1; totalDraw = 0; }
internal override void SetData(int subresource, Color4[] data) { int mipSlice, arrayIndex; CalculateArrayMipSlice(subresource, _subresources[0].Length, out mipSlice, out arrayIndex); Utilities.Copy(data, _subresources[arrayIndex][mipSlice].Data); }
public BasicVec4(Color4 v) { x = v.R; y = v.G; z = v.B; w = v.A; }
private static ColorRamp FromValues(string name, params OpenTK.Graphics.Color4[] colors) { var sizeX = 2; var sizeY = 1; var data = new Color4[sizeY, sizeX]; //var dX = sizeX / (float)colors.Length; //var dY = sizeY / (float)colors.Length; // var colorIndex = 0; for (int i = 0; i < sizeY; i++) { for (int j = 0; j < sizeX; j++) { //var t = dX * (j / colors.Length); var cindex = j % colors.Length; data[i, j] = colors[cindex]; } } var texture = new DataTexture<Color4> { Name = "color-ramp-" + name, InternalFormat = PixelInternalFormat.Rgb, Data2D = data, Params = new TextureBase.Parameters { GenerateMipmap = false, MinFilter = TextureMinFilter.Linear, MagFilter = TextureMagFilter.Linear }}; return new ColorRamp(name, texture); }
/// <summary> /// Initializes a new instance of the <see cref="BlendState" /> class. /// </summary> /// <param name="device">The device local.</param> /// <param name="description">The description.</param> /// <param name="blendFactor">The blend factor.</param> /// <param name="mask">The mask.</param> private BlendState(GraphicsDevice device, BlendStateDescription description, Color4 blendFactor, int mask) : base(device) { Description = description; BlendFactor = blendFactor; MultiSampleMask = mask; Initialize(new Direct3D11.BlendState(GraphicsDevice, Description)); }
/// <summary> /// Initializes a new instance of the <see cref="BlendState" /> class. /// </summary> /// <param name="device">The device local.</param> /// <param name="nativeState">State of the native.</param> /// <param name="blendFactor">The blend factor.</param> /// <param name="mask">The mask.</param> private BlendState(GraphicsDevice device, Direct3D11.BlendState nativeState, Color4 blendFactor, int mask) : base(device) { Description = nativeState.Description; BlendFactor = blendFactor; MultiSampleMask = mask; Initialize(nativeState); }
public override Color4[] GetData(int subresource) { var data = _subresources[subresource].Data; var result = new Color4[data.Length]; Utilities.Copy(data, result); return result; }
/// <summary> /// 粒子を作成する /// </summary> /// <param name="_x">中心座標</param> /// <param name="_d">直径</param> /// <param name="_color">表示色</param> public OutputParticle(Vector3 _x, float _d, Color4 _color) { // 各パラメーターを設定 this.X = _x; this.d = _d; this.color = _color; }
// Main constructor: public BooleanIndicator(RenderSet render_set, double x, double y) : base(render_set, x, y, 1.0, 1.0, null, Texture.Get("sprite_indicator")) { State = false; _Color = new Color4(Color.SkyBlue); _NextLayer = new LayeredSprite(render_set, x, y, 1.0, 1.0, null, Texture.Get ("sprite_indicator_gloss")); }
public TextSprite(Loc2D loc, string text, Color4 color) { EffectLoc = loc; Text = text; ActionDone = false; Color = color; }
/// <summary> /// Creates instance of EnvLight /// </summary> public EnvLight () { Position = Vector3.Zero; RadiusInner = 0; RadiusOuter = 1; Intensity = new Color4(1,1,1,0); }
/// <summary> /// position is top left of box. /// </summary> /// <param name="position"></param> /// <param name="size"></param> /// <param name="color"></param> public ColorBox(Vector2 position, Vector2 size, Color4 color) { this.position = position; this.size = size; model = Matrix4.CreateTranslation(position.X, position.Y, 0); Color = color; float[] vertices = new float[] { 0, 0, 0, size.Y, size.X, 0, size.X, size.Y }; uint[] indices = new uint[] { 0, 1, 2, 3 }; VBO vert = new VBO(), ind = new VBO(); vert.SetData(ref vertices, BufferUsageHint.StaticDraw); ind.SetData(ref indices, BufferUsageHint.StaticDraw); bufSet = new BufferSet(); bufSet.VertexBuffer = vert; bufSet.IndexBuffer = ind; bufSet.VertexSize = 2; bufSet.DrawMode = BeginMode.TriangleStrip; bufSet.SetDrawState(DrawStates.Vertex); }
public void Render(Vector3 pos, float rotation, Vector3 offset, Color4 color) { Vector3 rotate = new Vector3(0, 0, rotation); Vector2 dimension = new Vector2(_spriteWidth, _spriteHeight); Vector2 source = new Vector2(_xFrame * _spriteWidth, _yFrame * _spriteHeight); Graphics.DrawTexture(SpriteSheet, pos - offset, dimension, source, dimension, offset, rotate, color); }
public static void CI8(int Width, int Height, int LineSize, byte[] Source, int SourceOffset, ref byte[] Target, Color4[] PalColors) { int TargetOffset = 0; for (int j = 0; j < Height; j++) { for (int i = 0; i < Width / 2; i++) { if (SourceOffset >= Source.Length) return; byte CIIndex1 = (byte)((Source[SourceOffset] & 0xF0) >> 4); byte CIIndex2 = (byte)(Source[SourceOffset] & 0x0F); Target[TargetOffset] = (byte)PalColors[CIIndex1].R; Target[TargetOffset + 1] = (byte)PalColors[CIIndex1].G; Target[TargetOffset + 2] = (byte)PalColors[CIIndex1].B; Target[TargetOffset + 3] = (byte)PalColors[CIIndex1].A; Target[TargetOffset + 4] = (byte)PalColors[CIIndex2].R; Target[TargetOffset + 5] = (byte)PalColors[CIIndex2].G; Target[TargetOffset + 6] = (byte)PalColors[CIIndex2].B; Target[TargetOffset + 7] = (byte)PalColors[CIIndex2].A; SourceOffset++; TargetOffset += 8; } SourceOffset += LineSize * 8 - (Width / 2); } }
public static void DrawTexture(Texture2D texture, Vector2 position, Color4 color, float rotation, Vector2 origin, Vector2 scale) { DrawTexture(texture, new RectangleF(position.X, position.Y, texture.Width*scale.X, texture.Height*scale.Y), new RectangleF(0, 0, 1, 1), color, rotation, origin); }
private RadialGradientBrush CreateRadialGradientBrush(DeviceContext context, float width, float height, Color4 color1, Color4 color2, float color1Position, float color2Position) { GradientStop[] stops = new GradientStop[2]; //stops[0] = new GradientStop() { Color = new Color4(0.85f, 0, 0, 1.0f), Position = 0.0f }; //stops[1] = new GradientStop() { Color = new Color4(0.22f, 0, 0, 1.0f), Position = 1.0f }; stops[0] = new GradientStop() { Color = color1, Position = color1Position }; stops[1] = new GradientStop() { Color = color2, Position = color2Position }; GradientStopCollection gsc = new GradientStopCollection(context, stops, ExtendMode.Clamp); RadialGradientBrush brush = new RadialGradientBrush( context, new RadialGradientBrushProperties() { RadiusX = width / 1.3f, RadiusY = height / 1.3f, Center = new Vector2(width / 2.0f, height / 2.0f), GradientOriginOffset = new Vector2(0, 0) }, gsc); return brush; }
public Pixel(Color4 color) : this() { RedF = color.R; GreenF = color.G; BlueF = color.B; }
/// <summary> /// The base DrawTexture function. /// </summary> /// <param name="texture">The texture to draw</param> /// <param name="destRectangle">The destination rectangle, in pixel space, where the texture is drawn</param> /// <param name="sourceRectangle">The source within the texture, values must be between [0-1]</param> /// <param name="color">The color to be applied</param> /// <param name="rotation">The rotation, in degrees to be applied</param> /// <param name="origin">The origin of the rotation, this value is in pixel space referenced from the top left of destRectangle</param> public static void DrawTexture(Texture2D texture, RectangleF destRectangle, RectangleF sourceRectangle, Color4 color, float rotation, Vector2 origin) { RectangleF atlasRect = texture.TextureCoordRect; RectangleF sourceInAtlasCoords = new RectangleF(atlasRect.Left + atlasRect.Width * sourceRectangle.Left, atlasRect.Top + atlasRect.Height * sourceRectangle.Top, atlasRect.Width * sourceRectangle.Width, atlasRect.Height * sourceRectangle.Height); GL.Enable(EnableCap.Texture2D); GL.PushMatrix(); GL.Translate(destRectangle.Left + origin.X, destRectangle.Top + origin.Y, 0); GL.Rotate(rotation, 0.0f, 0.0f, 1.0f); GL.Translate(-origin.X, -origin.Y, 0); GL.BindTexture(TextureTarget.Texture2D, texture.ID); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); float width = destRectangle.Width; float height = destRectangle.Height; GL.Color4(color); GL.Begin(PrimitiveType.Quads); GL.TexCoord2(sourceInAtlasCoords.Left, sourceInAtlasCoords.Top); GL.Vertex2(0.0f, 0.0f); GL.TexCoord2(sourceInAtlasCoords.Right, sourceInAtlasCoords.Top); GL.Vertex2(width, 0.0f); GL.TexCoord2(sourceInAtlasCoords.Right, sourceInAtlasCoords.Bottom); GL.Vertex2(width, height); GL.TexCoord2(sourceInAtlasCoords.Left, sourceInAtlasCoords.Bottom); GL.Vertex2(0.0f, height); GL.End(); GL.PopMatrix(); GL.Disable(EnableCap.Texture2D); }
public Material(Color4 ambient, Color4 diffuse, Color4 specular, float specularExponent) { Ambient = ambient; Diffuse = diffuse; Specular = specular; SpecularExponent = specularExponent; }
/// <summary> /// Initializes with the specified colors. /// </summary> /// <param name="colors">The colors.</param> /// <msdn-id>ee719750</msdn-id> /// <unmanaged>HRESULT IWICPalette::InitializeCustom([In, Buffer] void* pColors,[In] unsigned int cCount)</unmanaged> /// <unmanaged-short>IWICPalette::InitializeCustom</unmanaged-short> public void Initialize(Color4[] colors) { var rawColors = new Color[colors.Length]; for (int i = 0; i < rawColors.Length; i++) rawColors[i] = (Color)colors[i]; Initialize(rawColors); }
/// <summary> /// 立方体を作成する /// </summary> /// <param name="_position">中心座標</param> /// <param name="_size">1辺の長さ</param> /// <param name="_color">表示色</param> public Cube(Vector3 _position, float _size, Color4 _color) { // 各パラメーターを設定 this.position = _position; this.size = _size; this.color = _color; }
/// <summary> /// Draws this shape using the given scale and offset. /// </summary> public void Draw(Render Render, Color4 Color, Vector Offset, double Scale) { Render.Vertex(Destination.TopLeft * Scale + Offset, Source.TopLeft, Color); Render.Vertex(Destination.BottomLeft * Scale + Offset, Source.BottomLeft, Color); Render.Vertex(Destination.BottomRight * Scale + Offset, Source.BottomRight, Color); Render.Vertex(Destination.TopRight * Scale + Offset, Source.TopRight, Color); }
/// <summary> /// 立方体を作成する /// </summary> /// <param name="_size">1辺の長さ</param> /// <param name="_color">表示色</param> public Cube(float _size, Color4 _color) { // 各パラメーターを設定 this.position = new Vector3(); this.size = _size; this.color = _color; }
public Vertex(Vector4 position, Color4 color, Vector2 textureCoordinate) { Position = position; Color = color; TextureCoordinate = textureCoordinate; _pad0 = Vector2.Zero; // important to align the vertex to a 16 byte boundary }
/// <summary> /// Draws this shape using the given modulating color and transform. /// </summary> public void Draw(Render Render, Color4 Color, Transform Transform) { Render.Vertex(Transform * Destination.TopLeft, Source.TopLeft, Color); Render.Vertex(Transform * Destination.BottomLeft, Source.BottomLeft, Color); Render.Vertex(Transform * Destination.BottomRight, Source.BottomRight, Color); Render.Vertex(Transform * Destination.TopRight, Source.TopRight, Color); }
public Material() { Ambient = new Color4(1, 1, 1); Diffuse = new Color4(1, 1, 1); Specular = new Color4(1, 1, 1); SpecularExponent = 0.1f; }
public static void AddInstance(string instanceName, ShaderResourceView srv, Vector2 pos, Color4 c, float s, SpriteBlendMode mode) { Matrix m = Matrix.Scaling(s, s, s) * Matrix.Translation(pos.X, pos.Y, 0); if (instances.ContainsKey(instanceName)) { instances[instanceName].Color = c; instances[instanceName].Transform = m; instances[instanceName].blendMode = mode; } else { CustomSpriteInstance si = new CustomSpriteInstance(srv, coordiantes, dimensions); si.Color = c; si.Transform = m; si.blendMode = mode; instances.Add(instanceName, si); } }
private void CreatePrim(WarpRenderer renderer, ISceneChildEntity prim) { try { const float MIN_SIZE = 2f; if ((PCode)prim.Shape.PCode != PCode.Prim) { return; } if (prim.Scale.LengthSquared() < MIN_SIZE * MIN_SIZE) { return; } Primitive omvPrim = prim.Shape.ToOmvPrimitive(prim.OffsetPosition, prim.GetRotationOffset()); FacetedMesh renderMesh = null; // Are we dealing with a sculptie or mesh? if (omvPrim.Sculpt != null && omvPrim.Sculpt.SculptTexture != UUID.Zero) { // Try fetchinng the asset byte[] sculptAsset = m_scene.AssetService.GetData(omvPrim.Sculpt.SculptTexture.ToString()); if (sculptAsset != null) { // Is it a mesh? if (omvPrim.Sculpt.Type == SculptType.Mesh) { AssetMesh meshAsset = new AssetMesh(omvPrim.Sculpt.SculptTexture, sculptAsset); FacetedMesh.TryDecodeFromAsset(omvPrim, meshAsset, DetailLevel.Highest, out renderMesh); meshAsset = null; } else // It's sculptie { Image sculpt = m_imgDecoder.DecodeToImage(sculptAsset); if (sculpt != null) { renderMesh = m_primMesher.GenerateFacetedSculptMesh(omvPrim, (Bitmap)sculpt, DetailLevel.Medium); sculpt.Dispose(); } } } } else // Prim { renderMesh = m_primMesher.GenerateFacetedMesh(omvPrim, DetailLevel.Medium); } if (renderMesh == null) { return; } warp_Vector primPos = ConvertVector(prim.GetWorldPosition()); warp_Quaternion primRot = ConvertQuaternion(prim.GetRotationOffset()); warp_Matrix m = warp_Matrix.quaternionMatrix(primRot); if (prim.ParentID != 0) { ISceneEntity group = m_scene.GetGroupByPrim(prim.LocalId); if (group != null) { m.transform(warp_Matrix.quaternionMatrix(ConvertQuaternion(group.RootChild.GetRotationOffset()))); } } warp_Vector primScale = ConvertVector(prim.Scale); string primID = prim.UUID.ToString(); // Create the prim faces for (int i = 0; i < renderMesh.Faces.Count; i++) { Face face = renderMesh.Faces[i]; string meshName = primID + "-Face-" + i.ToString(); warp_Object faceObj = new warp_Object(face.Vertices.Count, face.Indices.Count / 3); foreach (Vertex v in face.Vertices) { warp_Vector pos = ConvertVector(v.Position); warp_Vector norm = ConvertVector(v.Normal); if (prim.Shape.SculptTexture == UUID.Zero) { norm = norm.reverse(); } warp_Vertex vert = new warp_Vertex(pos, norm, v.TexCoord.X, v.TexCoord.Y); faceObj.addVertex(vert); } for (int j = 0; j < face.Indices.Count;) { faceObj.addTriangle( face.Indices[j++], face.Indices[j++], face.Indices[j++]); } Primitive.TextureEntryFace teFace = prim.Shape.Textures.GetFace((uint)i); string materialName; Color4 faceColor = GetFaceColor(teFace); if (m_texturePrims && prim.Scale.LengthSquared() > 48 * 48) { materialName = GetOrCreateMaterial(renderer, faceColor, teFace.TextureID); } else { materialName = GetOrCreateMaterial(renderer, faceColor); } faceObj.transform(m); faceObj.setPos(primPos); faceObj.scaleSelf(primScale.x, primScale.y, primScale.z); renderer.Scene.addObject(meshName, faceObj); renderer.SetObjectMaterial(meshName, materialName); } renderMesh.Faces.Clear(); renderMesh = null; } catch (Exception ex) { MainConsole.Instance.Warn("[Warp3D]: Exception creating prim, " + ex); } }
public static float[] ToFloats(this Color4 c) { return(new float[] { c.R, c.G, c.B, c.A }); }
public InternalDrawCommand(SpriteBatch spriteBatch, ref Vector2 fontSize, ref Vector2 position, ref Color4 color, float rotation, ref Vector2 origin, ref Vector2 scale, SpriteEffects spriteEffects, float depth) { SpriteBatch = spriteBatch; Position = position; Color = color; Rotation = rotation; Origin = origin; Scale = scale; SpriteEffects = spriteEffects; Depth = depth; FontSize = fontSize; }
/// <summary> /// Runs the demo. /// </summary> public void Run() { bool isFormClosed = false; bool formIsResizing = false; Form = new RenderForm(); /* * currentFormWindowState = Form.WindowState; * Form.Resize += (o, args) => * { * if (Form.WindowState != currentFormWindowState) * { * if (togglingFullScreen == false) * HandleResize(o, args); * } * * currentFormWindowState = Form.WindowState; * }; */ Form.ResizeBegin += (o, args) => { formIsResizing = true; }; Form.ResizeEnd += (o, args) => { Width = Form.ClientSize.Width; Height = Form.ClientSize.Height; renderView.Dispose(); depthView.Dispose(); _swapChain.ResizeBuffers(_swapChain.Description.BufferCount, Width, Height, _swapChain.Description.ModeDescription.Format, _swapChain.Description.Flags); CreateBuffers(); SetSceneConstants(); formIsResizing = false; }; //Form.Closed += (o, args) => { isFormClosed = true; }; Input = new Input(Form); Width = 1024; Height = 768; FullScreenWidth = Screen.PrimaryScreen.Bounds.Width; FullScreenHeight = Screen.PrimaryScreen.Bounds.Height; NearPlane = 1.0f; FarPlane = 200.0f; FieldOfView = (float)Math.PI / 4; Freelook = new FreeLook(Input); ambient = new Color4(Color.Gray.ToArgb()); try { OnInitializeDevice(); } catch (Exception e) { MessageBox.Show(e.ToString(), "Could not create DirectX 10 device."); return; } Initialize(); clock.Start(); RenderLoop.Run(Form, () => { OnHandleInput(); Update(); Render(); Input.ClearKeyCache(); }); }
/// <summary> /// Set the colour that things will be drawn in /// </summary> /// <param name="c"></param> public static void Colour(Color4 c) { colour = c; }
/// <summary> /// Set the background colour /// </summary> /// <param name="c"> /// Colour of the background /// </param> public static void Background(Color4 c) { GL.ClearColor(c); }
public abstract void DrawStringBaseline(string fontName, float size, string text, float x, float y, float start_x, Color4 color, bool underline = false, TextShadow shadow = default);
/// <summary> /// Called when [render]. /// </summary> /// <param name="context">The context.</param> /// <param name="deviceContext">The device context.</param> protected override void OnRender(RenderContext context, DeviceContextProxy deviceContext) { var buffer = context.RenderHost.RenderBuffer; bool hasMSAA = buffer.ColorBufferSampleDesc.Count > 1; var depthStencilBuffer = hasMSAA ? buffer.FullResDepthStencilPool.Get(Format.D32_Float_S8X24_UInt) : buffer.DepthStencilBuffer; BindTarget(depthStencilBuffer, buffer.FullResPPBuffer.CurrentRTV, deviceContext, buffer.TargetWidth, buffer.TargetHeight, false); if (hasMSAA) { //Needs to do a depth pass for existing meshes.Because the msaa depth buffer is not resolvable. deviceContext.ClearDepthStencilView(depthStencilBuffer, DepthStencilClearFlags.Depth, 1, 0); depthPrepassCore.Render(context, deviceContext); } var frustum = context.BoundingFrustum; //First pass, draw onto stencil buffer for (int i = 0; i < context.RenderHost.PerFrameNodesWithPostEffect.Count; ++i) { var mesh = context.RenderHost.PerFrameNodesWithPostEffect[i]; if (context.EnableBoundingFrustum && !mesh.TestViewFrustum(ref frustum)) { continue; } if (mesh.TryGetPostEffect(EffectName, out IEffectAttributes effect)) { currentCores.Add(new KeyValuePair <SceneNode, IEffectAttributes>(mesh, effect)); context.CustomPassName = DefaultPassNames.EffectMeshXRayGridP1; var pass = mesh.EffectTechnique[DefaultPassNames.EffectMeshXRayGridP1]; if (pass.IsNULL) { continue; } pass.BindShader(deviceContext); pass.BindStates(deviceContext, StateType.BlendState | StateType.DepthStencilState); mesh.RenderCustom(context, deviceContext); } } //Second pass, remove not covered part from stencil buffer for (int i = 0; i < currentCores.Count; ++i) { var mesh = currentCores[i].Key; context.CustomPassName = DefaultPassNames.EffectMeshXRayGridP2; var pass = mesh.EffectTechnique[DefaultPassNames.EffectMeshXRayGridP2]; if (pass.IsNULL) { continue; } pass.BindShader(deviceContext); pass.BindStates(deviceContext, StateType.BlendState | StateType.DepthStencilState); mesh.RenderCustom(context, deviceContext); } deviceContext.ClearDepthStencilView(depthStencilBuffer, DepthStencilClearFlags.Depth, 1, 0); modelCB.Upload(deviceContext, ref modelStruct); //Thrid pass, draw mesh with grid overlay for (int i = 0; i < currentCores.Count; ++i) { var mesh = currentCores[i].Key; var color = Color; if (currentCores[i].Value.TryGetAttribute(EffectAttributeNames.ColorAttributeName, out object attribute) && attribute is string colorStr) { color = colorStr.ToColor4(); } if (modelStruct.Color != color) { modelStruct.Color = color; modelCB.Upload(deviceContext, ref modelStruct); } context.CustomPassName = XRayDrawingPassName; var pass = mesh.EffectTechnique[XRayDrawingPassName]; if (pass.IsNULL) { continue; } pass.BindShader(deviceContext); pass.BindStates(deviceContext, StateType.BlendState | StateType.DepthStencilState); if (mesh.RenderCore is IMaterialRenderParams material) { material.MaterialVariables.BindMaterial(context, deviceContext, pass); } mesh.RenderCustom(context, deviceContext); } if (hasMSAA) { deviceContext.ClearRenderTagetBindings(); buffer.FullResDepthStencilPool.Put(Format.D32_Float_S8X24_UInt, depthStencilBuffer); } currentCores.Clear(); }
private void load(OverlayColourProvider?colourProvider, OsuColour colours) { Colour = defaultColour = colours.Gray8; hoverColour = colours.GrayF; highlightColour = colourProvider?.Highlight1 ?? colours.Green; }
public static Color4 HsvtoRgb(float h, float s, float v, bool hdr) { Color4 white = new Color4(1, 1, 1, 1); if (s == 0) { white.r = v; white.g = v; white.b = v; return(white); } if (v == 0) { white.r = 0; white.g = 0; white.b = 0; return(white); } white.r = 0; white.g = 0; white.b = 0; var num = s; var num2 = v; var f = h * 6; var num4 = MathUtils.Floor(f); var num5 = f - num4; var num6 = num2 * (1 - num); var num7 = num2 * (1 - (num * num5)); var num8 = num2 * (1 - (num * (1 - num5))); var num9 = num4; var flag = num9 + 1; if (flag == 0) { white.r = num2; white.g = num6; white.b = num7; } else if (flag == 1) { white.r = num2; white.g = num8; white.b = num6; } else if (flag == 2) { white.r = num7; white.g = num2; white.b = num6; } else if (flag == 3) { white.r = num6; white.g = num2; white.b = num8; } else if (flag == 4) { white.r = num6; white.g = num7; white.b = num2; } else if (flag == 5) { white.r = num8; white.g = num6; white.b = num2; } else if (flag == 6) { white.r = num2; white.g = num6; white.b = num7; } else if (flag == 7) { white.r = num2; white.g = num8; white.b = num6; } if (!hdr) { white.r = MathUtils.Clamp(white.r, 0, 1); white.g = MathUtils.Clamp(white.g, 0, 1); white.b = MathUtils.Clamp(white.b, 0, 1); } return(white); }
/// <summary> /// Creates a rectangular GameObject. The origin (0,0) is at the center of the GameWindow, and x and y /// use an origin at the center of the rectangle as well. /// </summary> /// <returns>The created GameObject, stored in the ObjectManager</returns> public ref GameObject CreateRectangle(int layer, int width, int height, int x, int y, Color4 color) { float xdist = width / 2; float ydist = height / 2; ColoredVertex[] vertices = { new ColoredVertex(new Vector4(-xdist, -ydist, 1.0f, 1.0f), color), new ColoredVertex(new Vector4(xdist, -ydist, 1.0f, 1.0f), color), new ColoredVertex(new Vector4(xdist, ydist, 1.0f, 1.0f), color), new ColoredVertex(new Vector4(-xdist, ydist, 1.0f, 1.0f), color) }; uint[] indices = { 0, 1, 2, 0, 2, 3 }; Vector3 position = new Vector3((float)x, (float)y, 0f); float rotX = 0f, rotY = 0f, rotZ = 0f; Vector3 scale = new Vector3(0.2f, 0.2f, 0.0f); int idx = GetNewGameObjectID(); _gameObjects[idx] = new GameObject( idx, 1, // renderID layer, vertices, indices, position, rotX, rotY, rotZ, scale); _gameObjectLayers[idx] = layer; return(ref _gameObjects[idx]); }
public static Color4 Lerp(Color4 a, Color4 b, float t) { t = MathUtils.Clamp01(t); return(new Color4(a.r + t * (b.r - a.r), a.g + t * (b.g - a.g), a.b + t * (b.b - a.b), a.a + t * (b.a - a.a))); }
private void load(OsuColour colour, AudioManager audio) { hoverColour = colour.Yellow; this.audio = audio; }
/// <summary> /// Smoothly adjusts the colour of <see cref="IContainer.EdgeEffect"/> over time. /// </summary> /// <returns>A <see cref="TransformSequence{T}"/> to which further transforms can be added.</returns> public static TransformSequence <T> FadeEdgeEffectTo <T>(this T container, Color4 newColour, double duration = 0, Easing easing = Easing.None) where T : IContainer => container.TransformTo(container.PopulateTransform(new TransformEdgeEffectColour(), newColour, duration, easing));
public static Color4 LerpUnclamped(Color4 a, Color4 b, float t) { return(new Color4(a.r + t * (b.r - a.r), a.g + t * (b.g - a.g), a.b + t * (b.b - a.b), a.a + t * (b.a - a.a))); }
/// <summary> /// Create a new reflection channel /// </summary> /// <param name="ReflectionColorMap"> Reflection map </param> /// <param name="ReflectionStrength"> Strenght of reflection </param> public Reflection(int ReflectionColorMap, float ReflectionStrength) { this.ReflectionColorMap = ReflectionColorMap; ReflectionColor = new Color4(0, 0, 0, 0); this.ReflectionStrength = ReflectionStrength; }
public Vertex(Vector3 position, Vector3 normal, Color4 color) { this.position = position; this.normal = normal; this.color = color; }
/// <summary> /// Create a new reflection channel /// </summary> /// <param name="ReflectionColorMap"> Reflection map </param> public Reflection(int ReflectionColorMap) { this.ReflectionColorMap = ReflectionColorMap; ReflectionColor = new Color4(0, 0, 0, 0); ReflectionStrength = 1; }
/// <summary> /// Create a new reflection channel /// </summary> /// <param name="ReflectionColor"> Reflection Color </param> /// <param name="ReflectionStrength"> Strenght of reflection </param> public Reflection(Color4 ReflectionColor, float ReflectionStrength) { ReflectionColorMap = -1; this.ReflectionColor = ReflectionColor; this.ReflectionStrength = ReflectionStrength; }
public override void Generate() { if (StartTime == EndTime) { StartTime = (int)Beatmap.HitObjects.First().StartTime; EndTime = (int)Beatmap.HitObjects.Last().EndTime; } EndTime = Math.Min(EndTime, (int)AudioDuration); StartTime = Math.Min(StartTime, EndTime); var bitmap = GetMapsetBitmap(SpritePath); var heightKeyframes = new KeyframedValue <float> [BarCount]; for (var i = 0; i < BarCount; i++) { heightKeyframes[i] = new KeyframedValue <float>(null); } var fftTimeStep = Beatmap.GetTimingPointAt(StartTime).BeatDuration / BeatDivisor; var fftOffset = fftTimeStep * 0.2; for (var time = (double)StartTime; time < EndTime; time += fftTimeStep) { var fft = GetFft(time + fftOffset, BarCount, null, FftEasing); for (var i = 0; i < BarCount; i++) { var height = (float)Math.Log10(1 + fft[i] * LogScale) * Scale.Y / bitmap.Height; if (height < MinimalHeight) { height = MinimalHeight; } heightKeyframes[i].Add(time, height); } } var layer = GetLayer("Spectrum"); var barWidth = Width / BarCount; for (var i = 0; i < BarCount; i++) { var keyframes = heightKeyframes[i]; keyframes.Simplify1dKeyframes(Tolerance, h => h); var bar = layer.CreateSprite(SpritePath, SpriteOrigin, new Vector2(Position.X + i * barWidth, Position.Y)); bar.CommandSplitThreshold = 300; var color = Color; if (ColorVariance > 0) { ColorVariance = MathHelper.Clamp(ColorVariance, 0, 1); var hsba = Color4.ToHsl(color); var sMin = Math.Max(0, hsba.Y - ColorVariance * 0.5f); var sMax = Math.Min(sMin + ColorVariance, 1); var vMin = Math.Max(0, hsba.Z - ColorVariance * 0.5f); var vMax = Math.Min(vMin + ColorVariance, 1); color = Color4.FromHsl(new Vector4( hsba.X, (float)Random(sMin, sMax), (float)Random(vMin, vMax), hsba.W)); } bar.Color(StartTime, color); bar.Additive(StartTime, EndTime); var scaleX = Scale.X * barWidth / bitmap.Width; scaleX = (float)Math.Floor(scaleX * 10) / 10.0f; var hasScale = false; keyframes.ForEachPair( (start, end) => { hasScale = true; bar.ScaleVec(start.Time, end.Time, scaleX, start.Value, scaleX, end.Value); }, MinimalHeight, s => (float)Math.Round(s, CommandDecimals) ); if (!hasScale) { bar.ScaleVec(StartTime, scaleX, MinimalHeight); } } }
/// <summary> /// Create a new reflection channel /// </summary> /// <param name="ReflectionColor"> Reflection Color </param> public Reflection(Color4 ReflectionColor) { ReflectionColorMap = -1; this.ReflectionColor = ReflectionColor; ReflectionStrength = 1; }
public override void RenderOverride(RenderContext localRenderContext) { base.RenderOverride(localRenderContext); AllocFont(); HorizontalTextAlignEnum horzAlign = HorizontalTextAlignEnum.Left; if (HorizontalContentAlignment == HorizontalAlignmentEnum.Right) { horzAlign = HorizontalTextAlignEnum.Right; } else if (HorizontalContentAlignment == HorizontalAlignmentEnum.Center) { horzAlign = HorizontalTextAlignEnum.Center; } VerticalTextAlignEnum vertAlign = VerticalTextAlignEnum.Top; if (VerticalContentAlignment == VerticalAlignmentEnum.Bottom) { vertAlign = VerticalTextAlignEnum.Bottom; } else if (VerticalContentAlignment == VerticalAlignmentEnum.Center) { vertAlign = VerticalTextAlignEnum.Center; } Color4 color = ColorConverter.FromColor(Color); color.Alpha *= (float)localRenderContext.Opacity; // Update text cursor if ((_cursorShapeInvalid || _cursorBrushInvalid) && CursorState == TextCursorState.Visible) { string textBeforeCaret = VisibleText; textBeforeCaret = string.IsNullOrEmpty(textBeforeCaret) ? string.Empty : textBeforeCaret.Substring(0, CaretIndex); float caretX = _asset.TextWidth(textBeforeCaret); float textHeight = _asset.TextHeight(1); float textInsetY; switch (vertAlign) { case VerticalTextAlignEnum.Bottom: textInsetY = _innerRect.Height - textHeight; break; case VerticalTextAlignEnum.Center: textInsetY = (_innerRect.Height - textHeight) / 2; break; default: // VerticalTextAlignEnum.Top textInsetY = 0; break; } if (_virtualPosition + caretX < 10) { _virtualPosition = _innerRect.Width / 3 - caretX; } if (_virtualPosition + caretX > _innerRect.Width - 10) { _virtualPosition = _innerRect.Width * 2 / 3 - caretX; } Bound(ref _virtualPosition, -caretX, 0); RectangleF cursorBounds = new RectangleF(_innerRect.X + _virtualPosition + caretX, _innerRect.Y + textInsetY, CURSOR_THICKNESS, textHeight); UpdateCursorShape(cursorBounds, localRenderContext.ZOrder); } // Render text _asset.Render(_innerRect, horzAlign, vertAlign, _virtualPosition, color, localRenderContext.ZOrder, localRenderContext.Transform); // Render text cursor if (_cursorBrush != null && CursorState == TextCursorState.Visible) { _cursorBrush.BeginRenderBrush(_cursorContext, localRenderContext); _cursorContext.Render(0); _cursorBrush.EndRender(); } }
private void loadTest(int testType) { TestContainer.Clear(); switch (testType) { default: { Container box; TestContainer.Add(box = new InfofulBoxAutoSize { Anchor = Anchor.Centre, Origin = Anchor.Centre, Masking = true, CornerRadius = 100, BorderColour = Color4.Aquamarine, BorderThickness = 3, EdgeEffect = new EdgeEffect { Type = EdgeEffectType.Shadow, Radius = 100, Colour = new Color4(0, 50, 100, 200), }, }); box.Add(box = new InfofulBox { Size = new Vector2(250, 250), Alpha = 0.5f, Origin = Anchor.Centre, Anchor = Anchor.Centre, Colour = Color4.DarkSeaGreen, }); box.OnUpdate += delegate { box.Rotation += 0.05f; }; break; } case 1: { Container box; TestContainer.Add(new InfofulBoxAutoSize { Anchor = Anchor.Centre, Origin = Anchor.Centre, Children = new[] { box = new InfofulBox { Masking = true, CornerRadius = 100, Size = new Vector2(400, 400), Alpha = 0.5f, Origin = Anchor.Centre, Anchor = Anchor.Centre, Colour = Color4.DarkSeaGreen, } } }); box.OnUpdate += delegate { box.Rotation += 0.05f; box.CornerRadius = 100 + 100 * (float)Math.Sin(box.Rotation * 0.01); }; break; } case 2: { Container box; TestContainer.Add(new InfofulBoxAutoSize { Anchor = Anchor.Centre, Origin = Anchor.Centre, Children = new[] { box = new InfofulBox { Masking = true, CornerRadius = 25, Shear = new Vector2(0.5f, 0), Size = new Vector2(150, 150), Scale = new Vector2(2.5f, 1.5f), Alpha = 0.5f, Origin = Anchor.Centre, Anchor = Anchor.Centre, Colour = Color4.DarkSeaGreen, } } }); box.OnUpdate += delegate { box.Rotation += 0.05f; }; break; } case 3: { Color4 glowColour = Color4.Aquamarine; glowColour.A = 0.5f; Container box1; Container box2; TestContainer.Add(new InfofulBoxAutoSize { Anchor = Anchor.Centre, Origin = Anchor.Centre, EdgeEffect = new EdgeEffect { Type = EdgeEffectType.Glow, Radius = 100, Roundness = 50, Colour = glowColour, }, BorderColour = Color4.Aquamarine, BorderThickness = 3, Children = new[] { box1 = new InfofulBoxAutoSize { Masking = true, CornerRadius = 25, Shear = new Vector2(0.5f, 0), Alpha = 0.5f, Origin = Anchor.Centre, Anchor = Anchor.Centre, Colour = Color4.DarkSeaGreen, Children = new[] { box2 = new InfofulBox { Masking = true, CornerRadius = 25, Shear = new Vector2(0.25f, 0.25f), Size = new Vector2(100, 200), Alpha = 0.5f, Origin = Anchor.Centre, Anchor = Anchor.Centre, Colour = Color4.Blue, } } } } }); box1.OnUpdate += delegate { box1.Rotation += 0.07f; }; box2.OnUpdate += delegate { box2.Rotation -= 0.15f; }; break; } case 4: { Func <float, Drawable> createMaskingBox = delegate(float scale) { float size = 200 / scale; return(new Container { Masking = true, CornerRadius = 25 / scale, BorderThickness = 12.5f / scale, BorderColour = Color4.Red, Size = new Vector2(size), Scale = new Vector2(scale), Anchor = Anchor.Centre, Origin = Anchor.Centre, Children = new Drawable[] { new Box { RelativeSizeAxes = Axes.Both, Colour = Color4.White, Anchor = Anchor.Centre, Origin = Anchor.Centre, }, new SpriteText { Text = @"Size: " + size + ", Scale: " + scale, TextSize = 20 / scale, Colour = Color4.Blue, Anchor = Anchor.Centre, Origin = Anchor.Centre, }, } }); }; TestContainer.Add(new FillFlowContainer { RelativeSizeAxes = Axes.Both, Children = new[] { new Container { RelativeSizeAxes = Axes.Both, Size = new Vector2(0.5f), Masking = true, Children = new[] { createMaskingBox(100) } }, new Container { RelativeSizeAxes = Axes.Both, Size = new Vector2(0.5f), Masking = true, Children = new[] { createMaskingBox(10) } }, new Container { RelativeSizeAxes = Axes.Both, Size = new Vector2(0.5f), Masking = true, Children = new[] { createMaskingBox(1) } }, new Container { RelativeSizeAxes = Axes.Both, Size = new Vector2(0.5f), Masking = true, Children = new[] { createMaskingBox(0.1f) } }, } }); break; } case 5: { TestContainer.Add(new Container { Masking = true, Size = new Vector2(0.5f), RelativeSizeAxes = Axes.Both, Children = new[] { new Container { Masking = true, CornerRadius = 100f, BorderThickness = 50f, BorderColour = Color4.Red, RelativeSizeAxes = Axes.Both, Size = new Vector2(1.5f), Anchor = Anchor.BottomRight, Origin = Anchor.Centre, Children = new Drawable[] { new Box { RelativeSizeAxes = Axes.Both, Colour = Color4.White, }, } } } }); break; } case 6: { TestContainer.Add(new FillFlowContainer { Direction = FillDirection.Vertical, AutoSizeAxes = Axes.Both, Spacing = new Vector2(0, 10), Children = new Drawable[] { new SpriteText { Text = $"None of the folowing {nameof(CircularContainer)}s should trigger until the white part is hovered" }, new FillFlowContainer { Direction = FillDirection.Vertical, AutoSizeAxes = Axes.Both, Spacing = new Vector2(0, 2), Children = new Drawable[] { new SpriteText { Text = "No masking" }, new CircularContainerWithInput { Size = new Vector2(200), Children = new Drawable[] { new Box { RelativeSizeAxes = Axes.Both, Colour = Color4.Red }, new CircularContainer { RelativeSizeAxes = Axes.Both, Colour = Color4.White, Masking = true, Children = new[] { new Box { RelativeSizeAxes = Axes.Both } } } } } } }, new FillFlowContainer { Direction = FillDirection.Vertical, AutoSizeAxes = Axes.Both, Spacing = new Vector2(0, 2), Children = new Drawable[] { new SpriteText { Text = "With masking" }, new CircularContainerWithInput { Size = new Vector2(200), Masking = true, Children = new Drawable[] { new Box { RelativeSizeAxes = Axes.Both, Colour = Color4.Red }, new CircularContainer { RelativeSizeAxes = Axes.Both, Colour = Color4.White, Masking = true, Children = new[] { new Box { RelativeSizeAxes = Axes.Both } } } } } } } } }); break; } } #if DEBUG //if (toggleDebugAutosize.State) // testContainer.Children.FindAll(c => c.HasAutosizeChildren).ForEach(c => c.AutoSizeDebug = true); #endif }
public void Draw(ImageCloud.FreeView freeview, AABB selectionAabb, Color4 selectionAabbColor, Size backbuffersize, int numdims = 3) { /*// Use custom projection matrix with z-far tailored to include all axes * float maxdist = 0.0f; * maxdist = Math.Max(maxdist, (new Vector3(1000.0f, 0.0f, 0.0f) - freeview.viewpos).Length); * maxdist = Math.Max(maxdist, (new Vector3(-1000.0f, 0.0f, 0.0f) - freeview.viewpos).Length); * maxdist = Math.Max(maxdist, (new Vector3(0.0f, 1000.0f, 0.0f) - freeview.viewpos).Length); * maxdist = Math.Max(maxdist, (new Vector3(0.0f, -1000.0f, 0.0f) - freeview.viewpos).Length); * maxdist = Math.Max(maxdist, (new Vector3(0.0f, 0.0f, 1000.0f) - freeview.viewpos).Length); * maxdist = Math.Max(maxdist, (new Vector3(0.0f, 0.0f, -1000.0f) - freeview.viewpos).Length); * Matrix4 viewprojmatrix = freeview.viewmatrix * Matrix4.CreatePerspectiveFieldOfView(ImageCloud.FOV_Y, (float)backbuffersize.Width / (float)backbuffersize.Height, maxdist / 10000.0f, maxdist);*/ Matrix4 viewprojmatrix = freeview.viewprojmatrix; Vector3 __axis_dist = new Vector3((new Vector2(freeview.viewpos.Y, freeview.viewpos.Z)).Length, (new Vector2(freeview.viewpos.X, freeview.viewpos.Z)).Length, (new Vector2(freeview.viewpos.X, freeview.viewpos.Y)).Length); Vector3 axis_dist = new Vector3(), _axis_dist = new Vector3(); for (int i = 0; i < numdims; ++i) { _axis_dist[i] = (float)Math.Log10(Math.Max(freeview.znear, __axis_dist[i])); axis_dist[i] = (float)Math.Pow(10.0, Math.Floor(_axis_dist[i])); } int[] floor_viewpos = new int[numdims]; float[] floor_viewpos10 = new float[numdims], axis_dist_fract = new float[numdims]; Matrix4[] scalematrix = new Matrix4[numdims]; for (int d = 0; d < numdims; ++d) { floor_viewpos[d] = Math.Abs((int)(Math.Floor(freeview.viewpos[d] / axis_dist[d] * 10.0f) / 10.0f)); floor_viewpos10[d] = Math.Abs((float)Math.Floor(freeview.viewpos[d] / axis_dist[d] / 10.0f) * axis_dist[d] * 10.0f); axis_dist_fract[d] = (_axis_dist[d] + 100.0f) % 1.0f; //EDIT: 100.0f ... constant to keep log positive scalematrix[d] = Matrix4.CreateScale(axis_dist[d]); } Vector3[] unitvector = { new Vector3(1.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f), new Vector3(0.0f, 0.0f, 1.0f) }; Matrix4[] tickrotmatrix = { Matrix4.CreateRotationY(MathHelper.PiOver2) * Matrix4.CreateRotationX(MathHelper.PiOver2), Matrix4.CreateRotationX(-MathHelper.PiOver2) * Matrix4.CreateRotationY(-MathHelper.PiOver2), Matrix4.Identity }; // >>> Draw axes GL.LineWidth(4.0f); axismesh.Bind(Common.sdrSolidColor); // Draw axes in positive directions Common.sdrSolidColor.Bind(viewprojmatrix); GL.Uniform4(Common.sdrSolidColor_colorUniform, POSITIVE_AXIS_COLOR); axismesh.Draw(0, 2 * numdims); // Draw axes in negative directions Common.sdrSolidColor.Bind(Matrix4.CreateRotationY(MathHelper.Pi) * Matrix4.CreateRotationZ(MathHelper.PiOver2) * viewprojmatrix); GL.Uniform4(Common.sdrSolidColor_colorUniform, NEGATIVE_AXIS_COLOR); axismesh.Draw(0, 2 * numdims); // >>> Draw selection AABB if (selectionAabb != null) { linemesh.Bind(Common.sdrSolidColor); Matrix4 selectionAabbTransform = selectionAabb.GetTransform(); Matrix4 offsetTransform = Matrix4.CreateTranslation(0.0f, 0.0f, -0.00001f); Common.sdrSolidColor.Bind(tickrotmatrix[0] * selectionAabbTransform * Matrix4.CreateScale(unitvector[0]) * viewprojmatrix * offsetTransform); GL.Uniform4(Common.sdrSolidColor_colorUniform, selectionAabbColor); linemesh.Draw(); Common.sdrSolidColor.Bind(tickrotmatrix[1] * selectionAabbTransform * Matrix4.CreateScale(unitvector[1]) * viewprojmatrix * offsetTransform); linemesh.Draw(); Common.sdrSolidColor.Bind(tickrotmatrix[2] * selectionAabbTransform * Matrix4.CreateScale(unitvector[2]) * viewprojmatrix * offsetTransform); linemesh.Draw(); } // >>> Draw ticks GL.LineWidth(2.0f); tickmesh.Bind(Common.sdrSolidColor); for (int d = 0; d < numdims; ++d) { if (__axis_dist[d] < freeview.znear) { continue; } for (int t = floor_viewpos[d] + LABEL_CAM_DISTANCE; t >= floor_viewpos[d]; --t) { if (t == 0) { continue; } Vector3 lblpos = unitvector[d] * (float)t * axis_dist[d]; float lbldist = (freeview.viewpos - lblpos).Length; float opacity = (float)Math.Pow(axis_dist_fract[d], LABEL_AXIS_DISTANCE_FADE); if (t % 10 == 0) { opacity *= 0.1f; } opacity += (float)Math.Pow(lbldist / LABEL_CAM_DISTANCE, LABEL_CAM_DISTANCE_FADE); float scale = axis_dist_fract[d]; if (t % 10 == 0) { scale *= 0.01f; } Color4 clr = t > 0 ? POSITIVE_AXIS_COLOR : NEGATIVE_AXIS_COLOR; clr.A = 1.0f - opacity; Common.sdrSolidColor.Bind(Matrix4.CreateScale(__axis_dist[d] * (1.0f - 0.5f * scale)) * tickrotmatrix[d] * Matrix4.CreateTranslation(lblpos) * viewprojmatrix); GL.Uniform4(Common.sdrSolidColor_colorUniform, clr); tickmesh.Draw(); } for (int t = floor_viewpos[d] - LABEL_CAM_DISTANCE; t < floor_viewpos[d]; ++t) { if (t == 0) { continue; } Vector3 lblpos = unitvector[d] * (float)t * axis_dist[d]; float lbldist = (freeview.viewpos - lblpos).Length; float opacity = (float)Math.Pow(axis_dist_fract[d], LABEL_AXIS_DISTANCE_FADE); if (t % 10 == 0) { opacity *= 0.1f; } opacity += (float)Math.Pow(lbldist / LABEL_CAM_DISTANCE, LABEL_CAM_DISTANCE_FADE); float scale = axis_dist_fract[d]; if (t % 10 == 0) { scale *= 0.01f; } Color4 clr = t > 0 ? POSITIVE_AXIS_COLOR : NEGATIVE_AXIS_COLOR; clr.A = 1.0f - opacity; Common.sdrSolidColor.Bind(Matrix4.CreateScale(__axis_dist[d] * (1.0f - 0.5f * scale)) * tickrotmatrix[d] * Matrix4.CreateTranslation(lblpos) * viewprojmatrix); GL.Uniform4(Common.sdrSolidColor_colorUniform, clr); tickmesh.Draw(); } } GL.LineWidth(1.0f); // >>> Draw labels Matrix4 vieworient = freeview.viewmatrix, invvieworient; vieworient.M41 = vieworient.M42 = vieworient.M43 = 0.0f; invvieworient = vieworient; invvieworient.Transpose(); for (int d = 0; d < numdims; ++d) { if (__axis_dist[d] < freeview.znear) { continue; } for (int t = floor_viewpos[d] + LABEL_CAM_DISTANCE; t >= floor_viewpos[d]; --t) { if (t == 0) { continue; } Vector3 lblpos = unitvector[d] * (float)t * axis_dist[d]; float lbldist = (freeview.viewpos - lblpos).Length; float opacity = (float)Math.Pow(axis_dist_fract[d], LABEL_AXIS_DISTANCE_FADE); if (t % 10 == 0) { opacity *= 0.1f; } opacity += (float)Math.Pow(lbldist / LABEL_CAM_DISTANCE, LABEL_CAM_DISTANCE_FADE); Color4 clr = new Color4(1.0f, 1.0f, 1.0f, 1.0f - opacity); //Vector3 offset = (freeview.viewpos - lblpos).Normalized() * 1.0f; Common.fontText2.DrawStringAt(lblpos /*+ offset*/, viewprojmatrix, ((decimal)t * (decimal)axis_dist[d]).ToString(), backbuffersize, clr); } for (int t = floor_viewpos[d] - LABEL_CAM_DISTANCE; t < floor_viewpos[d]; ++t) { if (t == 0) { continue; } Vector3 lblpos = unitvector[d] * (float)t * axis_dist[d]; float lbldist = (freeview.viewpos - lblpos).Length; float opacity = (float)Math.Pow(axis_dist_fract[d], LABEL_AXIS_DISTANCE_FADE); if (t % 10 == 0) { opacity *= 0.1f; } opacity += (float)Math.Pow(lbldist / LABEL_CAM_DISTANCE, LABEL_CAM_DISTANCE_FADE); Color4 clr = new Color4(1.0f, 1.0f, 1.0f, 1.0f - opacity); //Vector3 offset = (freeview.viewpos - lblpos).Normalized() * 1.0f; Common.fontText2.DrawStringAt(lblpos /*+ offset*/, viewprojmatrix, ((decimal)t * (decimal)axis_dist[d]).ToString(), backbuffersize, clr); } } // >>> Draw selection AABB labels if (selectionAabb != null) { for (int d = 0; d < numdims; ++d) { if (Math.Abs(selectionAabb.max[d] - selectionAabb.min[d]) < 0.1f) { continue; } float value = (selectionAabb.max[d] + selectionAabb.min[d]) / 2.0f; Vector3 lblpos = unitvector[d] * value; float lbldist = (freeview.viewpos - lblpos).Length; float opacity = 0.0f; opacity += (float)Math.Pow(lbldist / LABEL_CAM_DISTANCE, LABEL_CAM_DISTANCE_FADE); Color4 clr = selectionAabbColor; clr.A = 1.0f - opacity; Vector3 offset = (freeview.viewpos - lblpos).Normalized() * 1.0f; Common.fontText2.DrawStringAt(lblpos + offset, viewprojmatrix, ((decimal)value).ToString(), backbuffersize, clr); } } }
public void Deserialize(BSReader reader) { this.Time = reader.ReadInt32(); this.Value = reader.ReadColor4(); }
public static Vector4 ToVector4(this Color4 color) { return(new Vector4(color.R, color.G, color.B, color.A)); }
/// <inheritdoc /> public unsafe override void Initialize(ParticlePool pool, int startIdx, int endIdx, int maxCapacity) { if (!pool.FieldExists(ParticleFields.Color) || !pool.FieldExists(ParticleFields.RandomSeed)) { return; } // Collect the total number of living particles in the parent pool which have a Color field var parentPool = Parent?.Pool; var parentParticlesCount = parentPool?.LivingParticles ?? 0; var colorFieldParent = parentPool?.GetField(ParticleFields.Color) ?? ParticleFieldAccessor <Color4> .Invalid(); if (!colorFieldParent.IsValid()) { parentParticlesCount = 0; } var spawnControlField = GetSpawnControlField(); var colorField = pool.GetField(ParticleFields.Color); var rndField = pool.GetField(ParticleFields.RandomSeed); var sequentialParentIndex = 0; var sequentialParentParticles = 0; var parentIndex = 0; var i = startIdx; while (i != endIdx) { var particle = pool.FromIndex(i); var randSeed = particle.Get(rndField); var color = Color4.Lerp(ColorMin, ColorMax, randSeed.GetFloat(RandomOffset.Offset1A + SeedOffset)); // If there are living parent particles, the newly created particle will inherit Color from one of them if (parentParticlesCount > 0) { var parentParticleColor = new Color4(1, 1, 1, 1); // Spawn is fixed - parent particles have spawned a very specific number of children each if (spawnControlField.IsValid()) { while (sequentialParentParticles == 0) { // Early out - no more fixed number children. Rest of the particles (if any) are skipped intentionally if (sequentialParentIndex >= parentParticlesCount) { return; } parentIndex = sequentialParentIndex; var tempParentParticle = parentPool.FromIndex(parentIndex); sequentialParentIndex++; var childrenAttribute = (*((ParticleChildrenAttribute *)tempParentParticle[spawnControlField])); sequentialParentParticles = (int)childrenAttribute.ParticlesToEmit; } sequentialParentParticles--; var parentParticle = parentPool.FromIndex(parentIndex); parentParticleColor = (*((Color4 *)parentParticle[colorFieldParent])); } // Spawn is not fixed - pick a parent at random else { parentIndex = (int)(parentParticlesCount * randSeed.GetFloat(RandomOffset.Offset1A + ParentSeedOffset)); var parentParticle = parentPool.FromIndex(parentIndex); parentParticleColor = (*((Color4 *)parentParticle[colorFieldParent])); } color *= parentParticleColor; } // Premultiply alpha // This can't be done in advance for ColorMin and ColorMax because it will change the math color.R *= color.A; color.G *= color.A; color.B *= color.A; (*((Color4 *)particle[colorField])) = color; i = (i + 1) % maxCapacity; } }
public void DrawRectangle(MatrixLevels level, Rectangle rectangle, char token, bool solid, Color4 fore, Color4 back) { if (!solid) { for (int y = (int)rectangle.Top; y < rectangle.Bottom; y++) { SetToken(level, (int)rectangle.Left, y, token, fore, back); SetToken(level, (int)rectangle.Right - 1, y, token, fore, back); } for (int x = (int)rectangle.Left; x < rectangle.Right; x++) { SetToken(level, x, (int)rectangle.Top, token, fore, back); SetToken(level, x, (int)rectangle.Bottom - 1, token, fore, back); } } else { for (int y = (int)rectangle.Top; y < rectangle.Bottom; y++) { for (int x = (int)rectangle.Left; x < rectangle.Right; x++) { SetToken(level, x, y, token, fore, back); } } } }
/// <summary> /// Draw a sprite in the 3D world using the provided 3D sprite batch, world matrix and color. /// </summary> /// <param name="sprite">The sprite</param> /// <param name="spriteBatch">The sprite batch used to draw the sprite.</param> /// <param name="worldMatrix">The world matrix of the sprite</param> /// <param name="color">The color to apply on the sprite</param> /// <remarks>This function must be called between the <see cref="SpriteBatch.Begin(Xenko.Graphics.SpriteSortMode,Xenko.Graphics.Effect)"/> /// and <see cref="SpriteBatch.End()"/> calls of the provided <paramref name="spriteBatch"/></remarks> /// <exception cref="ArgumentException">The provided frame index is not valid.</exception> /// <exception cref="ArgumentOutOfRangeException">The provided spriteBatch is null</exception> public static void Draw3D(this Sprite sprite, Sprite3DBatch spriteBatch, ref Matrix worldMatrix, ref Color4 color) { spriteBatch.Draw(sprite.Texture, ref worldMatrix, ref sprite.RegionInternal, ref sprite.SizeInternal, ref color, sprite.Orientation); }
public static void DrawRect(float x, float y, float z, float width, float height, int lineWidth, Color4 color) { GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); GL.LineWidth(lineWidth); FillRect(x, y, z, width, height, color); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); }