コード例 #1
0
        public Texture FufillOrder(TextureRenderingTemplate template)
        {
            var outTextureInfo = template.OutTextureInfo;
            var shaderName     = template.ShaderName;
            var pack           = template.UniformPack;
            var material       = new Material(Shader.Find(shaderName));

            template.Keywords.EnableInMaterial(material);

            if (template.Coords != null)
            {
                pack.SetUniform("_Coords", template.Coords.ToVector4());
            }
            pack.SetUniformsToMaterial(material);

            var renderTextureFormat = template.RenderTextureFormat;

            Texture outTexture = null;

            if (template.CreateTexture2D)
            {
                Preconditions.Assert(!template.RenderTextureArraySlice.HasValue, "E629 RenderTextureArrays are not supported here");
                RenderTextureInfo renderTextureInfo = new RenderTextureInfo(outTextureInfo.Width, outTextureInfo.Height,
                                                                            renderTextureFormat, template.RenderTextureMipMaps);
                outTexture = UltraTextureRenderer.RenderTextureAtOnce(material, renderTextureInfo, outTextureInfo);
            }
            else
            {
                if (template.RenderingRectangle == null)
                {
                    Preconditions.Assert(!template.RenderTextureArraySlice.HasValue, "E629 RenderTextureArrays are not supported here");
                    RenderTextureInfo renderTextureInfo = new RenderTextureInfo(outTextureInfo.Width,
                                                                                outTextureInfo.Height,
                                                                                renderTextureFormat, template.RenderTextureMipMaps);
                    outTexture = UltraTextureRenderer.CreateRenderTexture(material, renderTextureInfo);
                }
                else
                {
                    if (template.RenderTextureArraySlice.HasValue)
                    {
                        UltraTextureRenderer.ModifyRenderTextureArray(material, template.RenderingRectangle, template.RenderTargetSize
                                                                      , template.RenderTextureToModify, template.RenderTextureArraySlice.Value);
                    }
                    else
                    {
                        UltraTextureRenderer.ModifyRenderTexture(material, template.RenderingRectangle, template.RenderTargetSize,
                                                                 template.RenderTextureToModify);
                    }

                    return(template.RenderTextureToModify);
                }
            }
            //GameObject.Destroy(material);
            return(outTexture);
        }
コード例 #2
0
        public RenderTexture EncodedHeightTextureToPlain(TextureWithSize encodedTexture)
        {
            var renderMaterial = new Material(Shader.Find("Custom/TerGen/RgbaToRFloat"));

            renderMaterial.SetTexture("_SourceTexture", encodedTexture.Texture);
            var textureSize       = encodedTexture.Size;
            var renderTextureInfo = new RenderTextureInfo(textureSize.X, textureSize.Y, RenderTextureFormat.RFloat, true);

            var tex = UltraTextureRenderer.CreateRenderTexture(renderMaterial, renderTextureInfo);

            return(tex);
        }
コード例 #3
0
 public async Task <Texture2D> PlainToEncodedHeightTextureAsync(TextureWithSize plainTexture)
 {
     return(await _commonExecutor.AddAction(() =>
     {
         var renderMaterial = new Material(Shader.Find("Custom/TerGen/RFloatToRgba"));
         renderMaterial.SetTexture("_SourceTexture", plainTexture.Texture);
         var textureSize = plainTexture.Size;
         var renderTextureInfo = new RenderTextureInfo(textureSize.X, textureSize.Y, RenderTextureFormat.ARGB32);
         ConventionalTextureInfo outTextureinfo =
             new ConventionalTextureInfo(textureSize.X, textureSize.Y, TextureFormat.ARGB32, false);
         return UltraTextureRenderer.RenderTextureAtOnce(renderMaterial, renderTextureInfo, outTextureinfo);
     }));
 }
コード例 #4
0
        private void GenerateTexture()
        {
            var heightTexture1 = SavingFileManager.LoadPngTextureFromFile(@"C:\inz\cont\temp3.png", 240,
                                                                          240, TextureFormat.RGBA32, true, true);
            Material material = new Material(Shader.Find("Custom/TerGen/ErosionThermal"));

            material.SetTexture("_MainInputTex", heightTexture1);

            RenderTextureInfo renderTextureInfo = new RenderTextureInfo(240, 240, RenderTextureFormat.ARGB32);

            ConventionalTextureInfo outTextureInfo = new ConventionalTextureInfo(240, 240, TextureFormat.ARGB32, false);

            OutputTexture = UltraTextureRenderer.RenderTextureAtOnce(material, renderTextureInfo, outTextureInfo);
            OutputShowingObject.GetComponent <MeshRenderer>().material.SetTexture("_MainTex", OutputTexture);
        }
コード例 #5
0
        public IntensityFieldFigure Generate(RandomFieldNature nature, float seed,
                                             MyRectangle segmentCoords) //todo use nature
        {
            UniformsPack uniforms = new UniformsPack();

            uniforms.SetUniform("_Seed", seed);
            uniforms.SetUniform("_Coords",
                                new Vector4(segmentCoords.X, segmentCoords.Y, segmentCoords.Width, segmentCoords.Height));

            Vector2 imageSize = new Vector2(
                (int)Mathf.Round(_configuration.PixelsPerUnit.x * segmentCoords.Width),
                (int)Mathf.Round(_configuration.PixelsPerUnit.y * segmentCoords.Height)
                );

            RenderTextureInfo renderTextureInfo = new RenderTextureInfo(
                (int)imageSize.x,
                (int)imageSize.y,
                RenderTextureFormat.ARGB32
                );

            ConventionalTextureInfo outTextureInfo = new ConventionalTextureInfo(
                (int)imageSize.x,
                (int)imageSize.y,
                TextureFormat.ARGB32
                );

            Texture2D outTexture = _textureRenderer.RenderTexture(_shaderName, _inputBlankTexture, uniforms,
                                                                  renderTextureInfo, outTextureInfo);

            var toReturn = CopyToRandomFieldFigure(outTexture);

            if (DebugLastGeneratedTexture != null)
            {
                GameObject.Destroy(DebugLastGeneratedTexture);
            }
            DebugLastGeneratedTexture = outTexture;
            //GameObject.Destroy(outTexture);

            return(toReturn);
        }