Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Shadows from Standard "Fade" texture created via C# script

Discussion in 'Editor & General Support' started by ShadyGuy, Oct 18, 2015.

  1. ShadyGuy

    ShadyGuy

    Joined:
    Oct 18, 2015
    Posts:
    13
    I'm going to explain my problem using screenshots.

    During runtime I create a RenderTexture that is shown using the Standard shader set up to use rendering mode "fade". In the editor it looks fine, casting a shadow and being transparent:

    01_inside_editor1.jpg

    However when I Build & Run a standalone exe file it is no longer transparent:

    02_standalone_exe1.jpg

    BUT if I add a Quad with a Material made inside the editor (using the standard shader and rendering mode "fade":

    03_inside_editor2.jpg

    Now all of a sudden when I Build & Run a standalone exe the RenderTexture appears correctly (casts a shadow and is transparent):

    04_standalone_exe2.jpg

    I haven't changed any code at all between taking these screenshots, the only difference is that I add that green quad in the editor. Somehow this affects how Unity is building the standalone exe.

    How can I make the Standard shader work correctly without having to use a Standard shader in the scene that is created inside the Unity Editor? (I need to create all my textures and materials via script during runtime.)
     
  2. ShadyGuy

    ShadyGuy

    Joined:
    Oct 18, 2015
    Posts:
    13
    Bump...
     
  3. ShadyGuy

    ShadyGuy

    Joined:
    Oct 18, 2015
    Posts:
    13
    I just noticed that this is also true if I want to make the Standard shader emissive.

    Code (csharp):
    1. myMeshRenderer.material.SetColor("_EmissionColor", new Color(1f, 1f, 1f));
    2. myMeshRenderer.material.EnableKeyword("_EMISSION");
    (The material is created from new Material(Shader.Find("Standard")) and then configured correctly to use the rendering mode "fade".)

    In the Unity Editor the texture gets a white overlay. If I Build & Run a standalone exe the texture does not.

    HOWEVER if I also add emission to the green dummy quad via the Unity Editor and then Build & Run a standalone exe THEN the texture appears like it should.

    What magic is this? What is the Unity Editor doing to make these things work all of a sudden?

    Note that the GameObject I work with in the Unity Editor has nothing to do with the material that is created via code yet somehow simply because it is there in the scene it somehow affect the stuff I create in C# and enables alpha (original topic of the thread) and emission to work correctly.
     
    Last edited: Oct 18, 2015
  4. ShadyGuy

    ShadyGuy

    Joined:
    Oct 18, 2015
    Posts:
    13
  5. ShadyGuy

    ShadyGuy

    Joined:
    Oct 18, 2015
    Posts:
    13
  6. ShadyGuy

    ShadyGuy

    Joined:
    Oct 18, 2015
    Posts:
    13
    We can bump if we want to
    We can age your threads behind
    Cause your threads don't bump
    And if they don't bump
    Well they're no threads of mine
     
  7. ShadyGuy

    ShadyGuy

    Joined:
    Oct 18, 2015
    Posts:
    13
  8. ShadyGuy

    ShadyGuy

    Joined:
    Oct 18, 2015
    Posts:
    13
  9. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,171
  10. ShadyGuy

    ShadyGuy

    Joined:
    Oct 18, 2015
    Posts:
    13
    "2. You must make sure Unity includes your required shader variants in the build"

    I guess what I want to do is impossible then, it's just a strange limitation with the Unity Engine.

    Thanks a lot for replying Jaimi!
     
  11. gamefish

    gamefish

    Joined:
    Jul 5, 2013
    Posts:
    14
    For me I spent a lot of time and finally find out that it's because my Standalone app uses default Graphics Quality: Fastest, but in Editor the default graphics quality seems to be Fantastic, which causes some texture behavior differences. Edit->Project Settings->Quality->Choose "Fastest" and then change "Texture Quality" from "Half Res" to "Full Res" and everything in Standalone build goes the same with Editor. 屏幕快照 2018-03-04 下午5.50.14.png
     
  12. executer

    executer

    Joined:
    Mar 29, 2017
    Posts:
    7
    can you please share your project files @ShadyGuy