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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

render only the inside of sphere and keep the transparency as well

Discussion in 'Shaders' started by Anrnzz, Mar 8, 2018.

  1. Anrnzz

    Anrnzz

    Joined:
    Oct 9, 2016
    Posts:
    7
    What I want to do is render the inside of this sphere and make the black part transparent:
    I have already figured out how to render inside of a sphere using this script: http://www.vrtiginous.com/flippingnormals, but by using this shader, there is no way to edit the albedo values just like what we did in the standard shader:
    inspector img here:
    Right now the view is from inside, as you can see, there is a black background behind those mountains. I hope to make the black part to be transparent.
    img:

    anyone knows how to fix this?
     
    Last edited: Mar 8, 2018
  2. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    10,982
    Why aren't you flipping the normals in your modelling software so you don't have to use special shaders for this?
     
  3. Anrnzz

    Anrnzz

    Joined:
    Oct 9, 2016
    Posts:
    7
    Hi, i am not using any modeling software because right now i only created one sphere in unity and attach a 360 degree image to it
     
  4. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    10,982
    Do you want the other functionality of the standard shader, or are you happy with how this looks and you only want it to look transparent?

    If it's the latter then replace a few lines in your shader code with this:

    Code (csharp):
    1.     SubShader {
    2.         Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
    3.         Cull Off
    4.  
    5.         CGPROGRAM
    6.         #pragma surface surf Lambert vertex:vert alpha
    I think that should do it.
     
  5. Anrnzz

    Anrnzz

    Joined:
    Oct 9, 2016
    Posts:
    7

    Hi, thank you for your help, but it's still not working.. still in black
     
  6. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    10,982
    That's weird. Try this:
    Code (csharp):
    1. Shader "FlipIt" {
    2.     Properties {
    3.         _Color ("Color", Color) = (1,1,1,1)
    4.         _MainTex ("Albedo (RGB)", 2D) = "white" {}
    5.         _Glossiness ("Smoothness", Range(0,1)) = 0.5
    6.         _Metallic ("Metallic", Range(0,1)) = 0.0
    7.     }
    8.     SubShader {
    9.         Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
    10.         LOD 200
    11.         Cull Front
    12.         CGPROGRAM
    13.  
    14.         #pragma surface surf Standard fullforwardshadows vertex:vert alpha:fade
    15.  
    16.         #pragma target 3.0
    17.  
    18.         sampler2D _MainTex;
    19.  
    20.         struct Input {
    21.             float2 uv_MainTex;
    22.         };
    23.  
    24.         half _Glossiness;
    25.         half _Metallic;
    26.         fixed4 _Color;
    27.  
    28.         UNITY_INSTANCING_BUFFER_START(Props)
    29.         UNITY_INSTANCING_BUFFER_END(Props)
    30.  
    31.         void vert(inout appdata_full v) {
    32.             v.normal.xyz = v.normal * -1;
    33.         }
    34.  
    35.         void surf (Input IN, inout SurfaceOutputStandard o) {
    36.             fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
    37.             o.Albedo = c.rgb;
    38.             o.Metallic = _Metallic;
    39.             o.Smoothness = _Glossiness;
    40.             o.Alpha = c.a;
    41.         }
    42.         ENDCG
    43.     }
    44.     FallBack "Diffuse"
    45. }
     
    unity_360mediatalo and Anrnzz like this.
  7. Anrnzz

    Anrnzz

    Joined:
    Oct 9, 2016
    Posts:
    7

    OMG! It WORKS! Thank you so much! ! you are a life saver!
     
  8. Anrnzz

    Anrnzz

    Joined:
    Oct 9, 2016
    Posts:
    7
    Hi, but there is one small issue, it seems that all the sprite/img I put inside the sphere can't show up...
     
  9. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    10,982
    Play with Render Queue (it's a number in your material settings, it controls the order things are drawn)
     
    Anrnzz likes this.