Author Topic: ProceduralMaterial to Texture2D black texture issue!  (Read 2823 times)

I am crushed.
I have tried converting a ProceduralTexture to a Texture2D countless times yet none of them worked. They all give the same result. A black texture. I believe the issue lies in the ProceduralMaterial not being readable event though I set it to be readable. My substance format is set to RAW.

The current code:

Code: [Select]
        substance = renderer.material as ProceduralMaterial;
       
        substance.isReadable = true;
        substanceTexture = substance.GetGeneratedTexture(substance.GetGeneratedTextures()[0].name);
        substanceTexture2D = new Texture2D(substanceTexture.width, substanceTexture.height, TextureFormat.ARGB32, false);
        substance.SetProceduralTexture("Hexagon_Heights", hexTexture);

        substance.RebuildTexturesImmediately();

        substanceTexture2D.SetPixels32(substanceTexture.GetPixels32(0, 0, substanceTexture.width, substanceTexture.height));
        substanceTexture2D.Apply();

Could someone help me out with this?
I don't see why Substance material doesn't have a Texture2D build into it...[/code]

Could you please send me a repro project so that I can have a look?

Also, which version of Unity are you using? Some versions had a bug where assigning a texture input to a ProceduralMaterial would not always tag it as 'dirty', and subsequent computations would not take place. This could explain the fact that you're only getting black pixels. You could try setting another parameter of the material to a new value right before calling RebuildTexturesImmediately(), just to check if it's that same issue.

Anyway, a repro case would be the quickest way to look at this.

Best Regards,
Eric

You're grabbing the generated texture at the wrong time.

Fixed code below:
Code: [Select]
        substance = renderer.material as ProceduralMaterial;
        substance.isReadable = true;

        // First assign the input texture
        substance.SetProceduralTexture("Hexagon_Heights", hexBiomeMap);
        // Then rebuild
        substance.RebuildTexturesImmediately();

        // Then grab the generated texture
        substanceTexture = substance.GetGeneratedTexture(substance.GetGeneratedTextures()[0].name);

        // Then grab the pixels from the generated texture and apply them to the Texture2D
        substanceTexture2D = new Texture2D(substanceTexture.width, substanceTexture.height, TextureFormat.ARGB32, false);
        substanceTexture2D.SetPixels32(substanceTexture.GetPixels32(0, 0, substanceTexture.width, substanceTexture.height));
        substanceTexture2D.Apply();

Best Regards,
Eric