Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

Help Wanted Transparent shell in sphere

Discussion in 'General Graphics' started by MatheusMarkies, Dec 1, 2021.

  1. MatheusMarkies

    MatheusMarkies

    Joined:
    Apr 16, 2017
    Posts:
    65
    Good Morning!
    I need help with a shader.
    I want to create a region of transparency on a sphere, in the shape of a spherical cap:
    dsaasdfsdfa.PNG

    This region in red should be transparent.
    First I tried to compare the uv with the measurement of the area that will be transparent, but it didn't work.

    Code (CSharp):
    1.    
    2. if(input.baseUV.x > 1- UNITY_ACCESS_INSTANCED_PROP(UnityPerMaterial, _CorneaAlpha))
    3.     return float4(color , 0);
    4.     else
    5.     return float4(color, 1);
    6.  
    How can I define a transparent shell on my object?
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    7,286
    if you invert color, instead of set alpha, does that show up?
     
  3. Torbach78

    Torbach78

    Joined:
    Aug 10, 2013
    Posts:
    235
    is the whole thing rendered transparently?

    if not you assign the object two materials in 3D software
    • Solid portion = [geometry]
    • cap portion = [transparent]: Blend SrcAlpha OneMinusAlpha (color 1,1,1,.5)
    otherwise the whole thing is transparent then make sure the blend mode supports something like Blend One OneMinusSrcAlpha, which will allow
    1,1,1,1 on the solid part = opaque
    .5,.5,.5,.5 = 50% transparent
     
    Last edited: Dec 1, 2021
  4. MatheusMarkies

    MatheusMarkies

    Joined:
    Apr 16, 2017
    Posts:
    65

    I can reproduce the object's transparency, but not in the format I want.
    I want to make an eye shader, and the transparency would be done on the cornea.
    Example:
    17_45_36_372_EyeProcedyralFaceCaustic_Shader_3.jpg

    But I don't think I can do this using just 1 material.

    Thanks for the answers!
     
  5. Torbach78

    Torbach78

    Joined:
    Aug 10, 2013
    Posts:
    235
    you can have 1 material but the shader is specialized; Over complexity solving the problem is not advised as well as not optimized since the whole thing is an overdraw*

    breaking the eye into portions (provided you are not hitting some drawcall/node limit on the CPU) and using two common shaders are re-usable (and already provided in the engine)

    * if you want 1 mat the entire eye alpha blends, the tint applied to the eye has alpha 1 while the cornea is alpha 0.05. and you still need that iris mesh and some smart UV's to divide up the solution
    PXL_20211201_191743011.jpg though alpha can be stored on vertex, no need for RGBA
     
    Last edited: Dec 1, 2021
    MatheusMarkies likes this.
unityunity