private void AddModel() { GameObject model; BrickType brickType = data.brickTypes.Find(x => (x.brickTypeKey == type)); if (brickType != null) { model = GameObject.Instantiate(brickType.brickObject); } else { Debug.LogError("Could not find model key matching " + type + " to set for this bricks model, Set to fall back model"); model = GameObject.Instantiate(fallBackModel); } // Initialise position model.transform.parent = modelHolder.transform; model.transform.localScale = Vector3.one; model.transform.localPosition = Vector3.zero; // Set Texture BrickTexture textureObject = data.textureData.Find(x => (x.textureKey == colour)); if (textureObject != null) { model.GetComponentInChildren <Renderer>().material.SetTexture("_BaseMap", textureObject.texture); } else { Debug.LogError("Could not find texture key matching " + colour + " to apply to this bricks model, Set to fall back texture"); model.GetComponentInChildren <Renderer>().material.SetTexture("_BaseMap", fallBackTexture); } }
static public Shader create_some_setup_shader() { var some_setup = new Shader(Client, Shader.ShaderType.Material) { Name = "some_setup ", UseMis = false, UseTransparentShadow = true, HeterogeneousVolume = false }; var brick_texture = new BrickTexture(); brick_texture.ins.Vector.Value = new float4(0.000f, 0.000f, 0.000f); brick_texture.ins.Color1.Value = new float4(0.800f, 0.800f, 0.800f); brick_texture.ins.Color2.Value = new float4(0.200f, 0.200f, 0.200f); brick_texture.ins.Mortar.Value = new float4(0.000f, 0.000f, 0.000f); brick_texture.ins.Scale.Value = 1.000f; brick_texture.ins.MortarSize.Value = 0.020f; brick_texture.ins.Bias.Value = 0.000f; brick_texture.ins.BrickWidth.Value = 0.500f; brick_texture.ins.RowHeight.Value = 0.250f; var checker_texture = new CheckerTexture(); checker_texture.ins.Vector.Value = new float4(0.000f, 0.000f, 0.000f); checker_texture.ins.Color1.Value = new float4(0.000f, 0.004f, 0.800f); checker_texture.ins.Color2.Value = new float4(0.200f, 0.000f, 0.007f); checker_texture.ins.Scale.Value = 5.000f; var diffuse_bsdf = new DiffuseBsdfNode(); diffuse_bsdf.ins.Color.Value = new float4(0.800f, 0.800f, 0.800f); diffuse_bsdf.ins.Roughness.Value = 0.000f; diffuse_bsdf.ins.Normal.Value = new float4(0.000f, 0.000f, 0.000f); var texture_coordinate = new TextureCoordinateNode(); some_setup.AddNode(brick_texture); some_setup.AddNode(checker_texture); some_setup.AddNode(diffuse_bsdf); some_setup.AddNode(texture_coordinate); brick_texture.outs.Color.Connect(diffuse_bsdf.ins.Color); checker_texture.outs.Color.Connect(brick_texture.ins.Mortar); texture_coordinate.outs.Normal.Connect(checker_texture.ins.Vector); texture_coordinate.outs.UV.Connect(brick_texture.ins.Vector); diffuse_bsdf.outs.BSDF.Connect(some_setup.Output.ins.Surface); some_setup.FinalizeGraph(); return(some_setup); }
private void Form1_Load(object sender, EventArgs e) { // Send the picture box references to the other scripts BrickTexture.SetPictureBoxes(GeneratedImage, GeneratedNormal); BrickHeightMap.SetPictureBoxes(GeneratedImage, GeneratedNormal); // Send image size to helper script Helper.SetImageSize((int)ImageHeightField.Value, (int)ImageHeightField.Value); // Call start function of bricktexture class BrickTexture.Start(); // All of the panels should be hidden at the start BrickPanel.Visible = false; }
// Send information to the BrickTexture class from the form // This also triggers the texture to be created public void SendBrickInfo(object sender, EventArgs e) { BrickTexture.Setup((int)BrickRowsField.Value, (int)BrickColumnsField.Value, (float)BrickCementRatio.Value * 0.01f, BrickColorDialog.Color, BrickCementColorDialog.Color); }
public static void CreateBrickHeightMap(Color brickColor) { BrickColor = brickColor; // Create normal map // At this point we have the basic setup of the brick texture // There are only two colors in the image so it is the perfect place to start creating the normal map GeneratedNormal.Image = new Bitmap(GeneratedNormal.Width, GeneratedNormal.Height); for (int i = 0; i < GeneratedNormal.Height; i++) { for (int j = 0; j < GeneratedNormal.Height; j++) { if (Helper.ColorComparison(((Bitmap)GeneratedImage.Image).GetPixel(i, j), BrickColor)) { ((Bitmap)GeneratedNormal.Image).SetPixel(i, j, Color.FromArgb(BrickHeight, BrickHeight, BrickHeight)); } else { ((Bitmap)GeneratedNormal.Image).SetPixel(i, j, Color.FromArgb(CementHeight, CementHeight, CementHeight)); } } } Random rand = new Random(); // Here we extrude the bricks to different levels for (int i = 0; i < GeneratedNormal.Height; i++) { for (int j = 0; j < GeneratedNormal.Width; j++) { // If pixel is part of the brick then we extrude it if (((Bitmap)GeneratedNormal.Image).GetPixel(j, i).R == BrickHeight) { int newColor = Helper.ColorRange(BrickHeight + rand.Next(1, BrickExtrusion)); ExtrudeBrick(j, i, Color.FromArgb(newColor, newColor, newColor)); /*int newColor = (int)((BrickTexture.AverageNoise(j, i) + 1) * BrickRoughness) + ((Bitmap)GeneratedImage.Image).GetPixel(j, i).R; * if (newColor < BrickHeight) { * newColor = BrickHeight; * } * ((Bitmap)GeneratedNormal.Image).SetPixel(j, i, Color.FromArgb(newColor, newColor, newColor));*/ } } } // Here we add some roughness to the bricks for (int i = 0; i < GeneratedNormal.Height; i++) { for (int j = 0; j < GeneratedNormal.Width; j++) { // If pixel is part of the brick if (((Bitmap)GeneratedImage.Image).GetPixel(j, i).R > CementHeight) { int newColor = (int)((BrickTexture.AverageNoise(j, i) + 1) * BrickRoughness) + ((Bitmap)GeneratedNormal.Image).GetPixel(j, i).R; if (newColor < BrickHeight) { newColor = BrickHeight; } ((Bitmap)GeneratedNormal.Image).SetPixel(j, i, Color.FromArgb(newColor, newColor, newColor)); } // Add roughness to the cement else { int newColor = (int)(BrickTexture.AverageNoise(j, i) * CementRoughness) + CementHeight; if (newColor < CementHeight) { newColor = CementHeight; } ((Bitmap)GeneratedNormal.Image).SetPixel(j, i, Color.FromArgb(newColor, newColor, newColor)); } } } }