Search Unity

Question convert godot shader into unity shader

Discussion in 'Shader Graph' started by demozbox, Jul 24, 2021.

  1. demozbox

    demozbox

    Joined:
    Nov 26, 2014
    Posts:
    83
    I need to convert godot shader into unity shader.
    The shader outlines 2dTexture and blooms the outline.
    Can anyone help me?
    Code (CSharp):
    1. shader_type canvas_item;
    2. uniform vec3 Scale;
    3. uniform float Amount;
    4. uniform float Offset;
    5. uniform vec4 Color : hint_color;
    6.  
    7.  
    8. // BlurCustom
    9.  
    10. vec4 blurWithAmountFunc(sampler2D _tex_b1r_cst, vec2 _uv_b1r_cst, float _l0d_b1r_cst, int _amnt_b1r_cst, float _0ffst_b1r_cst) {
    11.   vec4 _c0l_b1r_cst = vec4(0, 0, 0, 0);
    12.   _amnt_b1r_cst = int(max(min(float(_amnt_b1r_cst), 20.0), 0.0)); // have to do this int() float() S*** because of gles2
    13.                                   // max _amnt_b1r_cst is 20 for not to kill PC
    14.   for(int x = -_amnt_b1r_cst; x <= _amnt_b1r_cst; x++) {
    15.     for(int y = -_amnt_b1r_cst; y <= _amnt_b1r_cst; y++) {
    16.       vec2 _c00rd_b1r_cst = _uv_b1r_cst + vec2(float(x), float(y)) * _0ffst_b1r_cst;
    17.       if (_l0d_b1r_cst < 0.0){
    18.         _c0l_b1r_cst += texture(_tex_b1r_cst, _c00rd_b1r_cst);
    19.       }else{
    20.         _c0l_b1r_cst += textureLod(_tex_b1r_cst, _c00rd_b1r_cst, _l0d_b1r_cst);
    21.       }
    22.     }
    23.   }
    24.   int _nmb_ne1ghb0urs_b1r_cst = (_amnt_b1r_cst * 2 + 1) * (_amnt_b1r_cst * 2 + 1);
    25.   _c0l_b1r_cst /= float(_nmb_ne1ghb0urs_b1r_cst);
    26.   return _c0l_b1r_cst;
    27. }
    28.  
    29.  
    30. void vertex() {
    31. // Output:0
    32.  
    33. }
    34.  
    35. void fragment() {
    36. // Input:17
    37.  
    38. // Texture:25
    39.   vec3 n_out25p0;
    40.   float n_out25p1;
    41.   {
    42.     vec4 TEXTURE_tex_read = texture(TEXTURE, UV.xy);
    43.     n_out25p0 = TEXTURE_tex_read.rgb;
    44.     n_out25p1 = TEXTURE_tex_read.a;
    45.   }
    46.  
    47. // Input:18
    48.   vec3 n_out18p0 = vec3(UV, 0.0);
    49.  
    50. // VectorUniform:27
    51.   vec3 n_out27p0 = Scale;
    52.  
    53. // ScaleUV:26
    54.   vec3 n_in26p2 = vec3(0.50000, 0.50000, 0.00000);
    55.   vec3 n_out26p0;
    56.   {
    57.     n_out26p0.xy = (n_out18p0.xy - n_in26p2.xy) * n_out27p0.xy + n_in26p2.xy;
    58.   }
    59.  
    60. // ScalarUniform:13
    61.   float n_out13p0 = Amount;
    62.  
    63. // ScalarUniform:21
    64.   float n_out21p0 = Offset;
    65.  
    66. // BlurCustom:19
    67.   float n_in19p2 = -1.00000;
    68.   vec3 n_out19p0;
    69.   float n_out19p1;
    70.   {
    71.     vec4 n_out19p0n_out19p1 = blurWithAmountFunc(TEXTURE, n_out26p0.xy, n_in19p2, int(n_out13p0), n_out21p0);
    72.     n_out19p0 = n_out19p0n_out19p1.rgb;
    73.     n_out19p1 = n_out19p0n_out19p1.a;
    74.   }
    75.  
    76. // ColorUniform:23
    77.   vec3 n_out23p0 = Color.rgb;
    78.   float n_out23p1 = Color.a;
    79.  
    80. // ColorOp:22
    81.   vec3 n_out22p0;
    82.   {
    83.     float base = vec3(n_out19p1).x;
    84.     float blend = n_out23p0.x;
    85.     if (base < 0.5) {
    86.       n_out22p0.x = 2.0 * base * blend;
    87.     } else {
    88.       n_out22p0.x = 1.0 - 2.0 * (1.0 - blend) * (1.0 - base);
    89.     }
    90.   }
    91.   {
    92.     float base = vec3(n_out19p1).y;
    93.     float blend = n_out23p0.y;
    94.     if (base < 0.5) {
    95.       n_out22p0.y = 2.0 * base * blend;
    96.     } else {
    97.       n_out22p0.y = 1.0 - 2.0 * (1.0 - blend) * (1.0 - base);
    98.     }
    99.   }
    100.   {
    101.     float base = vec3(n_out19p1).z;
    102.     float blend = n_out23p0.z;
    103.     if (base < 0.5) {
    104.       n_out22p0.z = 2.0 * base * blend;
    105.     } else {
    106.       n_out22p0.z = 1.0 - 2.0 * (1.0 - blend) * (1.0 - base);
    107.     }
    108.   }
    109.  
    110. // ColorOp:24
    111.   vec3 n_out24p0 = min(n_out25p0, n_out22p0);
    112.  
    113. // Output:0
    114.   COLOR.rgb = n_out24p0;
    115.   COLOR.a = dot(n_out22p0, vec3(0.333333, 0.333333, 0.333333));
    116.  
    117. }
    118.  
    119. void light() {
    120. // Output:0
    121.  
    122. }
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Hi,

    I think you should post your shader code questions to the shaders section of this forum, not the shader graph (Graphics/Shaders)
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Godot uses a GLSL like shader language. You can look at some beginner Unity shader guides for how to setup a basic unlit shader, and then look for some GLSL to HLSL (the shader language Unity uses) guides to do the rest.