Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Issue with material data in -batchmode -nographics

Discussion in 'General Graphics' started by FoxUmkov_POP, Mar 14, 2023.

  1. FoxUmkov_POP

    FoxUmkov_POP

    Joined:
    Nov 6, 2018
    Posts:
    12
    Hello, while. moving to Unity 2022.2.9f1 from version 2019.2.19f1 i've faced to the problem. When i run standalone build in the "-batchmode -nographics" mode i can't get data information about material. However in normal mode it works correct. Wherein there are several errors that shader is not supported on this GPU. Is there any easy way to solve this problem?

    "ERROR: Shader Custom/Lightmapped_Diffuse_Rotation shader is not supported on this GPU (none of subshaders/fallbacks are suitable)"

    The "checker" script:
    Code (CSharp):
    1. using System.Text;
    2. using UnityEngine;
    3.  
    4. public class TestMats : MonoBehaviour
    5. {
    6.     public Material mat;
    7.     void Start()
    8.     {
    9.         Print(mat);
    10.  
    11. #if !UNITY_EDITOR
    12.         Application.Quit();
    13. #endif
    14.     }
    15.  
    16.     void Print(Material mat)
    17.     {
    18.         StringBuilder sb = new StringBuilder();
    19.         sb.Append($"mat: \n\t{mat.name}[{mat.shader.name}] \n\tmainTexture: {mat.mainTexture} \n\tcolor: {mat.color} \n\tGetColor(_Color): {mat.GetColor("_Color")} \n\tOffset: {mat.mainTextureOffset} \n\tScale: {mat.mainTextureScale}");
    20.         sb.Append($"\n\tmat.HasTexture: {mat.HasTexture("_MainTex")} \n\tmat.HasProperty(_MainTex): {mat.HasProperty("_MainTex")} \n\tHasFloat(_Angle): {mat.HasFloat("_Angle")} \n\tHasProperty(_Angle): {mat.HasProperty("_Angle")}");
    21.  
    22.         string[] floats = mat.GetPropertyNames(MaterialPropertyType.Float);
    23.         string[] vectors = mat.GetPropertyNames(MaterialPropertyType.Vector);
    24.         string[] textures = mat.GetPropertyNames(MaterialPropertyType.Texture);
    25.  
    26.         sb.Append($"\nFloat properties:\n\t {string.Join(", ", floats)}");
    27.         sb.Append($"\nVector properties:\n\t {string.Join(", ", vectors)}");
    28.         sb.Append($"\nTexture properties:\n\t {string.Join(", ", textures)}");
    29.         Debug.Log(sb.ToString());
    30.     }
    31.  
    32. }
    Check result, normal mode:
    '.\TestMats.exe' -logFile log_out.txt
    log_out.txt:


    [I]mat:
    Material[Custom/Lightmapped_Diffuse_Rotation]
    mainTexture: sample (UnityEngine.Texture2D)
    color: RGBA(1.000, 1.000, 1.000, 1.000)
    GetColor(_Color): RGBA(1.000, 1.000, 1.000, 1.000)
    Offset: (0.00, 0.00)
    Scale: (1.00, 1.00)
    mat.HasTexture: True
    mat.HasProperty(_MainTex): True
    HasFloat(_Angle): True
    HasProperty(_Angle): True
    Float properties:
    _ScaleX, _ScaleY, _Angle
    Vector properties:
    _MainTex_ST, _MainTex_TexelSize, _MainTex_HDR, _Color, _LightMap_ST, _LightMap_TexelSize, _LightMap_HDR
    Texture properties:
    _MainTex, _LightMap[/I]


    "-batchmode -nographics" mode:
    '.\TestMats.exe' -batchmode -nographics -logFile log_out_batch.txt
    log_out_batch.txt:


    [I]mat:
    Material[Custom/Lightmapped_Diffuse_Rotation]
    mainTexture: sample (UnityEngine.Texture2D)
    color: RGBA(0.000, 0.000, 0.000, 0.000)
    GetColor(_Color): RGBA(0.000, 0.000, 0.000, 0.000)
    Offset: (0.00, 0.00)
    Scale: (1.00, 1.00)
    mat.HasTexture: False
    mat.HasProperty(_MainTex): False
    HasFloat(_Angle): False
    HasProperty(_Angle): False
    Float properties:

    Vector properties:

    Texture properties:[/I]



    As it seems from log i can't get neither custom properties nor color set in material. This is repeated with both the standard shader and mine.

    Shader:
    Code (CSharp):
    1. Shader "Custom/Lightmapped_Diffuse_Rotation" {
    2. Properties {
    3.     _Color ("Main Color", Color) = (1,1,1,1)
    4.     _MainTex ("Base (RGB)", 2D) = "white" {}
    5.     _LightMap ("Lightmap (RGB)", 2D) = "black" {}
    6.     _Angle("Rotation", float) = 0
    7.     _ScaleX("ScaleX", float) = 1
    8.     _ScaleY("ScaleY", float) = 1
    9. }
    10.  
    11. SubShader {
    12.     LOD 200
    13.     Tags { "RenderType" = "Opaque" }
    14. CGPROGRAM
    15. #pragma surface surf Lambert
    16. float _Angle;
    17. float _ScaleX;
    18. float _ScaleY;
    19. float2 transform(float2 texcoord)
    20. {
    21.     float a = _Angle * 3.1415926535 / 180;
    22.     //float3 point = float3(texcoord.x - 0.5, texcoord.y - 0.5, 1);
    23.     float3x3 rotationMatrix = float3x3(cos(a), -sin(a), 0,
    24.                                             sin(a), cos(a), 0,
    25.                                             0, 0, 1);
    26.     float3 newPoint = mul(rotationMatrix, float3((texcoord.x) - 0.5, (texcoord.y) - 0.5, 1));      
    27.     return float2((newPoint.x + 0.5) * _ScaleX, (newPoint.y + 0.5) * _ScaleY);
    28. }
    29.  
    30. float2 transform2(float2 texcoord)
    31. {
    32.     float a = _Angle * 3.1415926535 / 180;
    33.     texcoord.xy -= 0.5;
    34.     float s = sin(a);
    35.     float c = cos(a);
    36.     float2x2 rotationMatrix = float2x2(c, -s, s, c);
    37.     rotationMatrix *= 0.5;
    38.     rotationMatrix += 0.5;
    39.     rotationMatrix = rotationMatrix * 2 - 1;
    40.  
    41.     texcoord.xy = mul(texcoord.xy, rotationMatrix);
    42.     texcoord.xy += 0.5;
    43.     return texcoord;
    44. }
    45.  
    46.  
    47. struct Input {
    48.   float2 uv_MainTex;
    49.   float2 uv2_LightMap;
    50. };
    51. sampler2D _MainTex;
    52. sampler2D _LightMap;
    53. fixed4 _Color;
    54. void surf (Input IN, inout SurfaceOutput o)
    55. {
    56.   o.Albedo = tex2D (_MainTex, transform(IN.uv_MainTex)).rgb * _Color;
    57.   half4 lm = tex2D (_LightMap, IN.uv2_LightMap);
    58.   o.Emission = lm.rgb*o.Albedo.rgb;
    59.   o.Alpha = lm.a * _Color.a;
    60. }
    61. ENDCG
    62. }
    63. FallBack "Legacy Shaders/Lightmapped/VertexLit"
    64. }
    65.  
     

    Attached Files:

  2. FoxUmkov_POP

    FoxUmkov_POP

    Joined:
    Nov 6, 2018
    Posts:
    12
    Hi all. After i didn’t find any answer to my problem i’ve decided to write additional component. It duplicates all properties of material and all properties(textures, colors, scale etc.) are applied by this script. Therefore in -batchmode -nographics mode i can easily get all necessary data by this script despite uncorrect work of material.