public void blit() { for (int i = 0; i < texture_order.Length; ++i) { if (texture_order[i] == null) { continue; } MaterialPropertyBlock mpb = null; MeshInfoPair mi = meshinfos[texture_order[i]]; for (int j = 1; j >= 0; --j) { var m = mi.m[j]; if (m.vertices.Count == 0) { continue; } m.mesh.Clear(); m.mesh.SetVertices(m.vertices); m.mesh.SetColors(m.colors); m.mesh.SetUVs(0, m.uvs); m.mesh.SetUVs(1, m.topleft); m.mesh.SetUVs(2, m.sizes); m.mesh.SetTriangles(m.indices, 0); if (j == 1) // outline { mpb = new MaterialPropertyBlock(); mpb.SetFloat("_OutlineSize", SpriteOutline.OutlineSize); mpb.SetColor("_OutlineColor", SpriteOutline.CurrentColor); } else { mpb = normal_mpb; } if (Game.instance != null && !texture_order[i].hud) { m.material.SetFloat("_UniBW", Game.instance.house.visibleDoorPosition() < 1.0f ? 1.0f : 0.0f); m.material.SetFloat("_UniPulseAmtX", Game.instance.house.visibleDoorPosition() < 1.0f ? (float)Math.Sin(Game.instance.time / 30.0f) * 6.0f : 0.0f); m.material.SetFloat("_UniPulseAmtY", Game.instance.house.visibleDoorPosition() < 1.0f ? (float)Math.Sin(Game.instance.time / 40.0f) * 6.0f : 0.0f); } else { m.material.SetFloat("_UniBW", 0.0f); m.material.SetFloat("_UniPulseAmtX", 0.0f); m.material.SetFloat("_UniPulseAmtY", 0.0f); } Graphics.DrawMesh(m.mesh, Matrix4x4.identity, m.material, layer, null, 0, mpb); } } }
public MeshInfoPair addTexture(GHTexture texture, int z_order) { MeshInfoPair m; if (meshinfos.ContainsKey(texture)) { m = meshinfos[texture]; /* NOTE(shane): this is required for pallet swapped assets */ if (texture.flag_z_order_reattach) { texture.flag_z_order_reattach = false; texture_order[z_order] = texture; } } else { m = new MeshInfoPair(); meshinfos[texture] = m; texture_order[z_order] = texture; } return(m); }
public void addSprite(GHTexture texture, Vector2 tl, Vector2 tr, Vector2 br, Vector2 bl, Bounds uv, Vector4 color, int stamp = 0, float amp = 0.0f, bool outline = false) { if (color.w == 0) { return; } texture.touch(); float z = -10 - texture.z_order; MeshInfoPair mp = addTexture(texture, texture.z_order); MeshInfo m = outline ? mp.m[1] : mp.m[0]; // outline is m[1], normal is m[0] m.material = texture.material; // this is a ref not a copy but that's okay float highlight_amt = 0; if (amp >= 1) { highlight_amt = color.x - 0.5f; color = Vector4.one; } // technically, topleft and sizes should not be vertex attributes, but uniforms. // however, the materialpropertyblock thingie doesn't seem to be working properly for some reason, // and this is pre-scissor so hey m.topleft.Add(tl); m.topleft.Add(tl); m.topleft.Add(tl); m.topleft.Add(tl); Vector2 sizes = br - tl; m.sizes.Add(sizes); m.sizes.Add(sizes); m.sizes.Add(sizes); m.sizes.Add(sizes); if (texture.scissored) { doScissor(ref uv, ref tl, ref tr, ref br, ref bl, ref color); } m.vertices.Add(new Vector3(tl.x, tl.y, z)); m.vertices.Add(new Vector3(tr.x, tr.y, z)); m.vertices.Add(new Vector3(br.x, br.y, z)); m.vertices.Add(new Vector3(bl.x, bl.y, z)); m.uvs.Add(uv.Point00); m.uvs.Add(uv.Point10); m.uvs.Add(uv.Point11); m.uvs.Add(uv.Point01); m.colors.Add(color); m.colors.Add(color); m.colors.Add(color); m.colors.Add(color); m.indices.Add(m.index); m.indices.Add(m.index + 2); m.indices.Add(m.index + 1); m.indices.Add(m.index); m.indices.Add(m.index + 3); m.indices.Add(m.index + 2); m.index += 4; // add highlight polygon to replicate amplification if (amp >= 1) { addSprite(AppMain.textures.highlight.texture, tl, tr, br, bl, new Bounds(new Vector2(0, 0), new Vector2(1, 1)), new Vector4(1, 1, 1, highlight_amt), stamp, 0, outline); } }