Example #1
0
        public VoxelVertexOutput ResolveVoxelVertex(VoxelVertexInput input, VoxelModelGenerationSettings settings)
        {
            VoxelVertexOutput output = new VoxelVertexOutput();

            output.SetDefaults(input, settings);

            VoxelMaterial mat = VoxelCellToMaterial(input.Cell);

            Assert.Message(mat != null, "Invalid material referenced by cell");

            if (mat != null)
            {
                mat.Properties.ApplyToVertex(input, ref output);
            }

            return(output);
        }
Example #2
0
        public VoxelVertexOutput ResolveVoxelVertex(VoxelVertexInput input, object scratch, VoxelModelGenerationSettings settings)
        {
            VoxelMaterial     material = (scratch as VoxelMaterialBaseVertexScratch).Material;
            VoxelVertexOutput output   = new VoxelVertexOutput();

            output.SetDefaults(input, material.RenderMaterial, settings);

            int matId = m_MaterialTable.GetMaterialIndex(material);

            output.UVs = new Vector4[2];

            // First channel is reserved
            // Calulcate face UVs (Don't bother clampping)
            Vector3Int absNormal = new Vector3Int(
                Mathf.Abs(input.Normal.x),
                Mathf.Abs(input.Normal.y),
                Mathf.Abs(input.Normal.z)
                );

            Vector3 uvPos = input.Coord + input.CoordOffset;
            Vector2 uvs   = new Vector2();

            if (absNormal.x > absNormal.y && absNormal.x > absNormal.z)
            {
                uvs = new Vector2(uvPos.y, uvPos.z);
            }
            else if (absNormal.y > absNormal.x && absNormal.y > absNormal.z)
            {
                uvs = new Vector2(uvPos.x, uvPos.z);
            }
            else
            {
                uvs = new Vector2(uvPos.x, uvPos.y);
            }

            output.UVs[0] = uvs + new Vector2(0.5f, 0.5f);
            output.UVs[1] = new Vector4(matId, 0, 0, 0);

            return(output);
        }
Example #3
0
        public VoxelVertexOutput ResolveVoxelVertex(VoxelVertexInput input, VoxelModelGenerationSettings settings)
        {
            float[]            channels  = ReadAllChannels(input.Coord);
            VoxelMaterialBasic material  = new VoxelMaterialBasic();
            List <Vector4>     customUVs = new List <Vector4>();

            int c = 0;

            foreach (var layout in m_Settings.TextureLayout)
            {
                switch (layout)
                {
                case CommonVoxelImportSettings.TextureLayoutFormat.Tint:
                    material.Tint = new Vector4(
                        channels[c + 0],
                        channels[c + 1],
                        channels[c + 2],
                        channels[c + 3]
                        );
                    break;

                case CommonVoxelImportSettings.TextureLayoutFormat.Albedo:
                    material.Colour.r = channels[c + 0];
                    material.Colour.g = channels[c + 1];
                    material.Colour.b = channels[c + 2];
                    break;

                case CommonVoxelImportSettings.TextureLayoutFormat.Alpha:
                    material.Colour.a = channels[c];
                    break;

                case CommonVoxelImportSettings.TextureLayoutFormat.CustomUV2:
                    customUVs.Add(new Vector4(channels[c + 0], channels[c + 1], 0, 0));
                    break;

                case CommonVoxelImportSettings.TextureLayoutFormat.CustomUV4:
                    customUVs.Add(new Vector4(channels[c + 0], channels[c + 1], channels[c + 2], channels[c + 3]));
                    break;

                case CommonVoxelImportSettings.TextureLayoutFormat.Specular:
                    material.Specular = channels[c];
                    break;

                case CommonVoxelImportSettings.TextureLayoutFormat.Roughness:
                    material.Roughness = channels[c];
                    break;
                }

                int channelSize = CommonVoxelImportSettings.GetChannelCount(layout);
                c += channelSize;
            }

            material.CustomUVs = customUVs.ToArray();

            VoxelVertexOutput output = new VoxelVertexOutput();

            output.SetDefaults(input, settings);

            material.ApplyToVertex(input, ref output);
            return(output);
        }