Search Unity

nothing drawn

Discussion in 'Shaders' started by acropole, Mar 15, 2020.

  1. acropole

    acropole

    Joined:
    Aug 13, 2009
    Posts:
    171
    Hi,

    Why does this code draw full black instead of an ellipse unlike on https://www.shadertoy.com/view/MdfGWn

    Code (CSharp):
    1. Shader "Custom/Ellipse"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex ("Albedo (RGB)", 2D) = "white" {}
    6.     }
    7.         SubShader
    8.         {
    9.             Tags { "RenderType" = "Opaque" }
    10.             LOD 200
    11.  
    12.             CGPROGRAM
    13.             // Physically based Standard lighting model, and enable shadows on all light types
    14.             #pragma surface surf Standard fullforwardshadows
    15.  
    16.             // Use shader model 3.0 target, to get nicer looking lighting
    17.             #pragma target 3.0
    18.  
    19.         sampler2D _MainTex;
    20.         uniform float4 _MainTex_TexelSize;
    21.  
    22.         struct Input
    23.         {
    24.             float2 uv_MainTex;
    25.         };
    26.  
    27.  
    28.         const float a = 1.0;
    29.         const float b = 3.0;
    30.         const float g = 2048.0;
    31.         float r = 0.9, e;
    32.  
    33.         float ellipse1(float2 p)
    34.         {
    35.             float f = length(p * float2(a, b));
    36.             return abs(f - r);
    37.         }
    38.  
    39.         void surf (Input IN, inout SurfaceOutputStandard o)
    40.         {
    41.             e = 2.0 / g;// _MainTex_TexelSize.z;
    42.          
    43. //            float2 uv = (2.0 * IN.uv_MainTex - _MainTex_TexelSize.zw) / _MainTex_TexelSize.z;
    44.             float2 uv = (2.0 * IN.uv_MainTex - float2(g, g)) / g;
    45.             fixed f1 = ellipse1(uv);
    46.  
    47.             o.Albedo = f1; // c.rgb;
    48.        
    49.             o.Alpha = 1.0;
    50.         }
    51.         ENDCG
    52.     }
    53.     FallBack "Diffuse"
    54. }
    55.