public void paint(Paintable paintable, Vector3 pos, float radius = 1f, float hardness = .5f, float strength = .5f, Color?color = null) { RenderTexture mask = paintable.getMask(); RenderTexture uvIslands = paintable.getUVIslands(); RenderTexture extend = paintable.getExtend(); RenderTexture support = paintable.getSupport(); Renderer rend = paintable.getRenderer(); paintMaterial.SetFloat(prepareUVID, 0); paintMaterial.SetVector(positionID, pos); paintMaterial.SetFloat(hardnessID, hardness); paintMaterial.SetFloat(strengthID, strength); paintMaterial.SetFloat(radiusID, radius); paintMaterial.SetTexture(textureID, support); paintMaterial.SetColor(colorID, color ?? Color.red); extendMaterial.SetFloat(uvOffsetID, paintable.extendsIslandOffset); extendMaterial.SetTexture(uvIslandsID, uvIslands); command.SetRenderTarget(mask); command.DrawRenderer(rend, paintMaterial, 0); command.SetRenderTarget(support); command.Blit(mask, support); command.SetRenderTarget(extend); command.Blit(mask, extend, extendMaterial); Graphics.ExecuteCommandBuffer(command); command.Clear(); }
public void initTextures(Paintable paintable) { RenderTexture mask = paintable.getMask(); RenderTexture uvIslands = paintable.getUVIslands(); RenderTexture extend = paintable.getExtend(); RenderTexture support = paintable.getSupport(); Renderer rend = paintable.getRenderer(); command.SetRenderTarget(mask); command.SetRenderTarget(extend); command.SetRenderTarget(support); paintMaterial.SetFloat(prepareUVID, 1); command.SetRenderTarget(uvIslands); command.DrawRenderer(rend, paintMaterial, 0); Graphics.ExecuteCommandBuffer(command); command.Clear(); }
public override void Update() { base.Update(); Vector3 rayOrgin = OverworldController.Player.transform.position; RaycastHit hit; int currentPaintFloor = -1; if (Physics.Raycast(rayOrgin, Vector3.down, out hit, 0.6f)) { Paintable paintableScript = hit.collider.gameObject.GetComponent <Paintable>(); if (paintableScript != null) { RenderTexture maskTexture = paintableScript.getExtend(); Vector2 hitCoordinate = hit.textureCoord; RenderTexture singlePixelTexture = new RenderTexture(1, 1, 0); Graphics.CopyTexture( maskTexture, 0, 0, (int)(hitCoordinate.x * 1024), (int)(hitCoordinate.y * 1024), 1, 1, singlePixelTexture, 0, 0, 0, 0 ); RenderTexture.active = singlePixelTexture; Texture2D tex = new Texture2D(1, 1, TextureFormat.RGBA32, false); tex.ReadPixels(new Rect(0, 0, 1, 1), 0, 0); Color underPixel = tex.GetPixel(0, 0); RenderTexture.active = null; singlePixelTexture.Release(); if (underPixel.a > 0.8f) { Vector3 underPixelVector = new Vector3(underPixel.r, underPixel.g, underPixel.b); float smallestDistance = 10000; int colorIdx = 0; foreach (Color abilityColor in abilityColors) { Vector3 abilityColorVector = new Vector3(abilityColor.r, abilityColor.g, abilityColor.b); float colorDistance = Vector3.Distance(underPixelVector, abilityColorVector); if (colorDistance < smallestDistance) { smallestDistance = colorDistance; currentPaintFloor = colorIdx; } colorIdx += 1; } } } } Debug.Log(currentPaintFloor); if (currentPaintFloor == 1) { OverworldController.Player.GetComponent <CharacterMovementOverworld>().ForceJump(20); } }