private static Material[] BuildMaterialsBlendModes(string shaderName) { var shader = P3dShader.Load(shaderName); var materials = new Material[P3dShader.BLEND_MODE_COUNT]; for (var blend = 0; blend < P3dShader.BLEND_MODE_COUNT; blend++) { materials[blend] = P3dShader.Build(shader, 0, (P3dBlendMode)blend); } return(materials); }
public static void Normal(RenderTexture rendertexture, Texture texture) { if (cachedNormalSet == false) { cachedNormal = P3dShader.BuildMaterial("Hidden/Paint in 3D/Normal"); cachedNormalSet = true; } cachedNormal.SetTexture(P3dShader._Texture, texture); P3dHelper.Blit(rendertexture, cachedNormal); }
public static void Premultiply(RenderTexture rendertexture, Texture texture, Color tint) { if (cachedPremultiplySet == false) { cachedPremultiply = P3dShader.BuildMaterial("Hidden/Paint in 3D/Premultiply"); cachedPremultiplySet = true; } cachedPremultiply.SetTexture(P3dShader._Texture, texture); cachedPremultiply.SetColor(P3dShader._Color, tint); P3dHelper.Blit(rendertexture, cachedPremultiply); }
public static Material[] BuildMaterialsBlendModes(string shaderName) { var shader = P3dShader.Load(shaderName); var materials = new Material[P3dBlendMode.COUNT]; for (var index = 0; index < P3dBlendMode.COUNT; index++) { var material = P3dShader.Build(shader); P3dShader.BuildBlendMode(material, index); materials[index] = material; } return(materials); }
public static void Texture(RenderTexture rendertexture, Mesh mesh, int submesh, Texture texture, P3dCoord coord) { if (cachedTextureSet == false) { cachedTexture = P3dShader.BuildMaterial("Hidden/Paint in 3D/Texture"); cachedTextureSet = true; } P3dHelper.BeginActive(rendertexture); cachedTexture.SetTexture(P3dShader._Buffer, texture); cachedTexture.SetVector(P3dShader._BufferSize, new Vector2(texture.width, texture.height)); P3dHelper.Draw(cachedTexture, mesh, Matrix4x4.identity, submesh, coord); P3dHelper.EndActive(); }
public static void White(RenderTexture rendertexture, Mesh mesh, int submesh, P3dCoord coord) { P3dHelper.BeginActive(rendertexture); if (mesh != null) { if (cachedWhiteSet == false) { cachedWhite = P3dShader.BuildMaterial("Hidden/Paint in 3D/White"); cachedWhiteSet = true; } GL.Clear(true, true, Color.black); P3dHelper.Draw(cachedWhite, mesh, Matrix4x4.identity, submesh, coord); } else { GL.Clear(true, true, Color.white); } P3dHelper.EndActive(); }
public static Material[] BuildMaterialsBlendModes(string shaderName, string keyword = null) { var shader = P3dShader.Load(shaderName); var materials = new Material[P3dBlendMode.COUNT]; for (var index = 0; index < P3dBlendMode.COUNT; index++) { var material = P3dShader.Build(shader); P3dShader.BuildBlendMode(material, index); materials[index] = material; } if (string.IsNullOrEmpty(keyword) == false) { for (var index = 0; index < P3dBlendMode.COUNT; index++) { materials[index].EnableKeyword(keyword); } } return(materials); }
static P3dCommandDecal() { cachedSpotMaterials = P3dShader.BuildMaterialsBlendModes("Hidden/Paint in 3D/Decal"); cachedLineMaterials = P3dShader.BuildMaterialsBlendModes("Hidden/Paint in 3D/Decal", "P3D_LINE"); cachedQuadMaterials = P3dShader.BuildMaterialsBlendModes("Hidden/Paint in 3D/Decal", "P3D_QUAD"); }
private void BakeOverlap() { var desc = new RenderTextureDescriptor(1024, 1024, RenderTextureFormat.ARGB32, 0); var renderTexture = P3dHelper.GetRenderTexture(desc); if (overlapMaterial == null) { overlapMaterial = P3dShader.BuildMaterial("Hidden/Paint in 3D/Overlap"); } overlapMaterial.SetVector(P3dShader._Coord, P3dHelper.IndexToVector(coord)); var oldActive = RenderTexture.active; RenderTexture.active = renderTexture; GL.Clear(true, true, Color.black); overlapMaterial.SetPass(0); Graphics.DrawMeshNow(mesh, Matrix4x4.identity, submesh); foreach (var obj in Selection.objects) { var otherMesh = obj as Mesh; if (otherMesh != null && otherMesh != mesh) { Graphics.DrawMeshNow(otherMesh, Matrix4x4.identity, submesh); } } RenderTexture.active = oldActive; overlapTex = P3dHelper.GetReadableCopy(renderTexture); P3dHelper.ReleaseRenderTexture(renderTexture); var utilizationCount = 0; var overlapCount = 0; for (var y = 0; y < overlapTex.height; y++) { for (var x = 0; x < overlapTex.width; x++) { var pixel = overlapTex.GetPixel(x, y); if (pixel.r > 0.0f) { if (pixel.r > 1.5 / 255.0f) { pixel = Color.red; overlapCount += 1; } else { pixel = Color.gray; } utilizationCount += 1; overlapTex.SetPixel(x, y, pixel); } } } var total = overlapTex.width * overlapTex.height * 0.01f; utilizationPercent = utilizationCount / total; overlapPercent = overlapCount / total; overlapTex.Apply(); }
private static Material BuildMaterial(string shaderName) { var shader = P3dShader.Load(shaderName); return(P3dShader.Build(shader)); }
static P3dCommandSphere() { cachedSpotMaterial = P3dShader.BuildMaterial("Hidden/Paint in 3D/Sphere"); cachedLineMaterial = P3dShader.BuildMaterial("Hidden/Paint in 3D/Sphere", "P3D_LINE"); cachedQuadMaterial = P3dShader.BuildMaterial("Hidden/Paint in 3D/Sphere", "P3D_QUAD"); }
static P3dCommandReplace() { cachedMaterial = P3dShader.BuildMaterial("Hidden/Paint in 3D/Replace"); }
static P3dCommandFill() { cachedMaterials = P3dShader.BuildMaterialsBlendModes("Hidden/Paint in 3D/Fill"); }
public static void BuildMaterial(ref Material material, ref int materialHash, string path, string keyword = null) { material = P3dShader.BuildMaterial(path, keyword); materialHash = P3dSerialization.TryRegister(material); }
static P3dCommandFill() { cachedMaterial = P3dShader.BuildMaterial("Hidden/Paint in 3D/Fill"); }
private void Bake(RenderTexture temporary, int width, int height, RenderTextureFormat format, int scale) { if (bakedPixels == null) { bakedPixels = new List <bool>(); } else { bakedPixels.Clear(); } baked = true; bakedMesh = mesh; bakedSize = new Vector2Int(width, height); if (cachedMaterial == null) { cachedMaterial = P3dShader.BuildMaterial("Hidden/Paint in 3D/White"); } cachedMaterial.SetVector(P3dShader._Channel, P3dHelper.IndexToVector((int)PaintableTexture.Coord)); // Write to temp RenderTexture var oldActive = RenderTexture.active; var renderTexture = temporary; if (temporary == null) { var desc = new RenderTextureDescriptor(width, height, format, 0); renderTexture = P3dHelper.GetRenderTexture(desc); } RenderTexture.active = renderTexture; GL.Clear(true, true, Color.black); cachedMaterial.SetPass(0); Graphics.DrawMeshNow(mesh, Matrix4x4.identity, PaintableTexture.Slot.Index); RenderTexture.active = oldActive; // Get readable copy var readable = P3dHelper.GetReadableCopy(renderTexture); if (temporary == null) { P3dHelper.ReleaseRenderTexture(renderTexture); } // Run through pixels to count total and build binary mask bakedPixels.Capacity = width * height; total = 0; for (var y = 0; y < height; y++) { for (var x = 0; x < width; x++) { if (readable.GetPixel(x, y).r > 0.5f) { bakedPixels.Add(true); total += scale; } else { bakedPixels.Add(false); } } } // Clean up P3dHelper.Destroy(readable); }