コード例 #1
0
        public static void SetTextures(Rect terrainRect, Texture2D[] textures, int[] maskGroupNums, VegetationPackagePro package)
        {
            for (int i = 0; i < textures.Length; i++)
            {
                Texture2D tex = textures[i];
                if (tex == null)
                {
                    continue;
                }

                TextureMaskGroup maskGroup = package.TextureMaskGroupList[maskGroupNums[i]];

                //creating new mask only if the mask with the same rect doesn't exist
                TextureMask mask = maskGroup.TextureMaskList.Find(m => m.TextureRect == terrainRect);
                if (mask == null)
                {
                    mask = new TextureMask {
                        TextureRect = terrainRect
                    };
                    maskGroup.TextureMaskList.Add(mask);
                }

                mask.MaskTexture = tex;
            }

            //VegetationSystemPro system = GameObject.FindObjectOfType<VegetationSystemPro>();
            //if (system != null)
            //	system.ClearCache(); //clearing cache causes flickering
            VegetationStudioManager.RefreshTerrainHeightMap();
        }
コード例 #2
0
    public static TextureImporter Make(TextureProcessor textureProcessor, Figure figure, string uvSetName, int surfaceIdx)
    {
        var uvSet = figure.UvSets[uvSetName];
        var mask  = TextureMask.Make(uvSet, figure.Geometry.SurfaceMap, surfaceIdx);

        return(new TextureImporter(textureProcessor, mask));
    }
コード例 #3
0
 public void Merge(TextureMask mask)
 {
     if (masksByUvSet.TryGetValue(mask.UvSet, out var existingMask))
     {
         existingMask.Merge(mask);
     }
     else
     {
         masksByUvSet.Add(mask.UvSet, mask);
     }
 }
コード例 #4
0
    public void Merge(TextureMask other)
    {
        if (uvSet != other.uvSet)
        {
            throw new InvalidOperationException("texture file conflict");
        }

        if (surfaceMap != other.surfaceMap)
        {
            throw new InvalidOperationException("texture type conflict");
        }

        surfaceIdxs.UnionWith(other.surfaceIdxs);
    }
コード例 #5
0
    public void Merge(FileInfo file, TextureProcessingType type, bool isLinear, TextureMask mask)
    {
        if (this.file.FullName != file.FullName)
        {
            throw new InvalidOperationException("texture file conflict");
        }

        this.type = MergeType(this.type, type);

        if (this.isLinear != isLinear)
        {
            throw new InvalidOperationException("texture isLinear conflict");
        }

        this.mask.Merge(mask);
    }
コード例 #6
0
    public void RenderMaskToAlpha(TextureMask mask, Size2 size, Texture2D destTexture)
    {
        var vertices = mask.GetMaskVertices();

        // Not sure by, possibly a nvidia bug, but the vertex buffer padding by an extra element is necessary.
        // Otherwise (0,0) gets passed to the vertex shader instead of the last vertex.
        var vertexBufferSizeInBytes = Vector2.SizeInBytes * (vertices.Length + 1);
        var vertexBuffer            = SharpDX.Direct3D11.Buffer.Create(device, BindFlags.VertexBuffer, vertices, vertexBufferSizeInBytes);

        var indices     = mask.GetMaskTriangleIndices();
        var indexBuffer = SharpDX.Direct3D11.Buffer.Create(device, BindFlags.IndexBuffer, indices.ToArray());

        var renderTargetView = new RenderTargetView(device, destTexture);

        var context = device.ImmediateContext;

        context.ClearState();

        context.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
        context.InputAssembler.InputLayout       = inputLayout;
        context.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(vertexBuffer, Vector2.SizeInBytes, 0));
        context.InputAssembler.SetIndexBuffer(indexBuffer, SharpDX.DXGI.Format.R32_UInt, 0);

        context.VertexShader.Set(vertexShader);

        context.Rasterizer.SetViewport(0, 0, size.Width, size.Height);
        context.Rasterizer.State = rasterizerState;

        context.PixelShader.Set(pixelShader);

        context.OutputMerger.SetBlendState(blendState);
        context.OutputMerger.SetRenderTargets(renderTargetView);

        context.DrawIndexed(indices.Count, 0, 0);

        context.ClearState();

        vertexBuffer.Dispose();
        indexBuffer.Dispose();
        renderTargetView.Dispose();
    }
コード例 #7
0
        public static void FlushTextures(Rect terrainRect, VegetationPackagePro package)
        {
            if (package == null)
            {
                return;
            }

            foreach (TextureMaskGroup maskGroup in package.TextureMaskGroupList)
            {
                for (int i = maskGroup.TextureMaskList.Count - 1; i >= 0; i--)
                {
                    TextureMask mask = maskGroup.TextureMaskList[i];
                    if (mask.MaskTexture == null || mask.TextureRect == terrainRect)
                    {
                        mask.Dispose();
                        maskGroup.TextureMaskList.RemoveAt(i);
                        //if (system != null) system.SelectedTextureMaskGroupTextureIndex = 0;
                    }
                }
            }

            //if (system != null)
            //	system.ClearCache();
        }
コード例 #8
0
    public string RegisterForProcessing(FileInfo textureFile, TextureProcessingType type, bool isLinear, TextureMask mask)
    {
        string name = Path.GetFileNameWithoutExtension(textureFile.FullName);

        if (type == TextureProcessingType.Bump)
        {
            name += "-to-normal";
        }

        if (!settingsByName.TryGetValue(name, out var settings))
        {
            settings = new TextureProcessingSettings(textureFile, type, isLinear, mask);
            settingsByName.Add(name, settings);
        }
        else
        {
            settings.Merge(textureFile, type, isLinear, mask);
        }

        return(path + "/" + name);
    }
コード例 #9
0
 public TextureProcessingSettings(FileInfo file, TextureProcessingType type, bool isLinear, TextureMask mask)
 {
     this.file     = file;
     this.type     = type;
     this.isLinear = isLinear;
     this.mask.Merge(mask);
 }
コード例 #10
0
    private void DumpNormals(TextureProcessor textureProcessor, DirectoryInfo shapeDirectory, ShapeImportConfiguration shapeImportConfiguration, ChannelInputs shapeInputs)
    {
        var normalsConf     = shapeImportConfiguration?.normals;
        var baseNormalsConf = baseConfiguration?.normals;

        if (normalsConf == null && baseNormalsConf == null)
        {
            return;
        }

        var recipeFile = shapeDirectory.File("shape-normals.dat");

        if (recipeFile.Exists)
        {
            return;
        }

        var surfaceGroups = normalsConf?.surfaceGroups ?? baseNormalsConf?.surfaceGroups;

        var uvSetName = normalsConf?.uvSet ?? baseNormalsConf?.uvSet ?? figure.DefaultUvSet.Name;
        var uvSet     = figure.UvSets[uvSetName];

        var surfaceNames = figure.Geometry.SurfaceNames;
        Dictionary <string, int> surfaceNameToIdx = Enumerable.Range(0, surfaceNames.Length)
                                                    .ToDictionary(idx => surfaceNames[idx], idx => idx);

        bool generateFromHd                 = normalsConf?.generatedFromHd ?? false;
        var  generatedTextureDirectory      = CommonPaths.WorkDir.Subdirectory("generated-textures");
        NormalMapRenderer normalMapRenderer = null;

        string[] textureNamesBySurface = Enumerable.Repeat(ShapeNormalsRecipe.DefaultTextureName, surfaceNames.Length).ToArray();

        for (int groupIdx = 0; groupIdx < surfaceGroups.Count; ++groupIdx)
        {
            var surfaceIdxs = surfaceGroups[groupIdx]
                              .Select(surfaceName => surfaceNameToIdx[surfaceName])
                              .ToList();

            FileInfo textureFile;
            if (!generateFromHd)
            {
                var texturePath = normalsConf?.textures?[groupIdx];
                if (texturePath == null)
                {
                    continue;
                }

                textureFile = fileLocator.Locate(texturePath).File;
            }
            else
            {
                textureFile = generatedTextureDirectory.File($"normal-map-{shapeImportConfiguration.name}-{groupIdx}.png");
                if (!textureFile.Exists)
                {
                    if (normalMapRenderer == null)
                    {
                        Console.WriteLine($"Generating normals for shape '{shapeImportConfiguration.name}'...");
                        normalMapRenderer = hdMorphToNormalMapConverter.MakeNormalMapRenderer(figure, uvSet, shapeInputs);
                    }

                    var normalMap = normalMapRenderer.Render(new HashSet <int>(surfaceIdxs));
                    generatedTextureDirectory.CreateWithParents();
                    normalMap.Save(textureFile);
                    normalMap.Dispose();
                }
            }

            foreach (int surfaceIdx in surfaceIdxs)
            {
                var mask        = TextureMask.Make(uvSet, figure.Geometry.SurfaceMap, surfaceIdx);
                var textureName = textureProcessor.RegisterForProcessing(textureFile, TextureProcessingType.Normal, true, mask);
                textureNamesBySurface[surfaceIdx] = textureName;
            }
        }

        normalMapRenderer?.Dispose();

        var recipe = new ShapeNormalsRecipe(uvSetName, textureNamesBySurface);

        textureProcessor.RegisterAction(() => {
            shapeDirectory.CreateWithParents();
            Persistance.Save(recipeFile, recipe);
        });
    }
コード例 #11
0
 public TextureImporter(TextureProcessor textureProcessor, TextureMask mask)
 {
     this.textureProcessor = textureProcessor;
     this.mask             = mask;
 }