Search Unity

[SOLVED] Illuminating Sphere from inside for 360 Photo

Discussion in 'Shaders' started by TheMasterGabriel, Feb 28, 2017.

  1. TheMasterGabriel

    TheMasterGabriel

    Joined:
    Feb 28, 2017
    Posts:
    3
    Hi,
    I am currently trying to make a 360 degree photo viewer in unity. I have a test 360 photo that seems to be lit fine when I look at it outside my Unity environment, but when I try to view it within a sphere, it gets really dark. I am hoping to eventually export my project as an app, so I'm building from the GoogleVR demo. I have tried several things and I can't seem to figure it out. As a note, I'm using a shader that I found to invert my sphere so I can see the texture from the inside. Here it is:

    Code (csharp):
    1. Shader "Custom/MediaShader"
    2.  
    3. {
    4.     Properties {
    5.         _Color("Color", Color) = (1,1,1,1)
    6.         _MainTex("Albedo (RGB)", 2D) = "white" {}
    7.         _Glossiness("Smoothness", Range(0,1)) = 0.5
    8.         _Metallic("Metallic", Range(0,1)) = 0.0
    9.     }
    10.    
    11.     SubShader {
    12.         Tags{ "RenderType" = "Opaque" }
    13.         LOD 200
    14.         cull off
    15.  
    16.         CGPROGRAM
    17.         // Physically based Standard lighting model, and enable shadows on all light types
    18.         #pragma surface surf Standard fullforwardshadows
    19.  
    20.         // Use shader model 3.0 target, to get nicer looking lighting
    21.         #pragma target 3.0
    22.  
    23.         sampler2D _MainTex;
    24.  
    25.         struct Input {
    26.             float2 uv_MainTex;
    27.         };
    28.  
    29.         half _Glossiness;
    30.         half _Metallic;
    31.         fixed4 _Color;
    32.  
    33.         void surf(Input IN, inout SurfaceOutputStandard o) {
    34.             // Albedo comes from a texture tinted by color
    35.             fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    36.             o.Albedo = c.rgb;
    37.             // Metallic and smoothness come from slider variables
    38.             o.Metallic = _Metallic;
    39.             o.Smoothness = _Glossiness;
    40.             o.Alpha = c.a;
    41.         }
    42.         ENDCG
    43.     }
    44.    
    45.     FallBack "Diffuse"
    46. }


    Basically, is there a way to adapt this shader so that I can light my sphere from the inside as well? If pictures are needed to further explain, let me know. Thanks - TMG

    Also note that I tried adding light sources within the sphere itself, but to no avail.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    Step one: Don't use a surface shader, use a basic vertex fragment shader like that created by creating a new unlit shader in the editor.
    Step two: Add Cull Off to that shader (see your original shader for an example of where to put it).
    Step three: Profit!
     
    TheMasterGabriel likes this.
  3. TheMasterGabriel

    TheMasterGabriel

    Joined:
    Feb 28, 2017
    Posts:
    3
    Thanks, that worked!
     
  4. Flurgle

    Flurgle

    Joined:
    May 16, 2016
    Posts:
    389
    @bgolus, your solution works becase the surface shader is more directly connected to unity lighting model where as vert is not? Just curious
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    Sort of. A surface shader is a vertex fragment shader generator, so it's not that the surface shader is "more directly connected" to Unity's lighting systems than a vertex fragment shader, it ultimately is a vertex fragment shader after all, just one that it includes all of the code to use the lighting values being past to it by Unity's rendering systems.

    Technically this problem could have been solved by using a surface shader's Emission property as that works pretty much exactly like the basic vertex fragment shader of just rendering the color you set unmodified, but then you're also still doing all of the work to calculate lighting you don't need or want.
     
    Flurgle likes this.