EArkham Posted Friday at 05:28 PM Report Posted Friday at 05:28 PM (edited) Anyone know what causes this strange four-colour issue? The sprite I'm using is a custom png image, but it's all white with transparency and the problem occurs even when I swap to other images. The colour split is centered precisely on the crosshair. For example, if I move the crosshair down and to my right, the entire sprite will appear green -- which means screen space issue, rather than vertex colour issue. I assume I'm doing something stupid in the code but I'm either ignorant or blind to it from staring at it too long. Relevant code below in spoiler: Spoiler public BeaconGlowRenderer(ICoreClientAPI capi) { this.capi = capi; textureId = capi.Render.GetOrLoadTexture( new AssetLocation( "amazingilluminations", "textures/particles/beacon-glow.png" ) ); } public void OnRenderFrame(float deltaTime, EnumRenderStage stage) { if (BeaconLightBlockEntity.Positions.Count == 0) return; var render = capi.Render; var shader = render.PreparedStandardShader(0, 0, 0); shader.NormalShaded = 1; shader.Tex2D = textureId; shader.RgbaTint = ColorUtil.WhiteArgbVec; var positions = BeaconLightBlockEntity.Positions; var data = new MeshData( positions.Count * 4, positions.Count * 6, withNormals: false, withUv: true, withRgba: true, withFlags: true ); float[] view = render.CurrentModelviewMatrix; foreach (BlockPos pos in positions) { float x = pos.X + 0.5f; float y = pos.Y + 0.5f; float z = pos.Z + 0.5f; float vx = view[0] * x + view[4] * y + view[8] * z + view[12]; float vy = view[1] * x + view[5] * y + view[9] * z + view[13]; float vz = view[2] * x + view[6] * y + view[10] * z + view[14]; int i = data.VerticesCount; //int color = unchecked((int)0xffffffff); data.AddWithFlagsVertex(vx - GlowSize, vy - GlowSize, vz, 0, 1, unchecked((int)0xFFFFFFFF), 0); data.AddWithFlagsVertex(vx + GlowSize, vy - GlowSize, vz, 1, 1, unchecked((int)0xFFFFFFFF), 0); data.AddWithFlagsVertex(vx + GlowSize, vy + GlowSize, vz, 1, 0, unchecked((int)0xFFFFFFFF), 0); data.AddWithFlagsVertex(vx - GlowSize, vy + GlowSize, vz, 0, 0, unchecked((int)0xFFFFFFFF), 0); data.AddQuadIndices(i); } mesh = render.UploadMesh(data); float[] identity = Mat4f.Create(); Mat4f.Identity(identity); shader.ViewMatrix = identity; shader.ModelMatrix = identity; shader.ProjectionMatrix = render.CurrentProjectionMatrix; render.GlToggleBlend(true, EnumBlendMode.Standard); render.RenderMesh(mesh); render.GlToggleBlend(false); render.DeleteMesh(mesh); mesh = null; shader.Stop(); } Edited Friday at 05:29 PM by EArkham Image didn't attach on initial post
Recommended Posts