How to see a sphere from inside it
I know this was questioned LOTS of times, but i couldn't find an answer for it. Most of the scripts that people made to correct this are outdated, the tutorials don't work anymore, and i couldn't find any shader that could do that or something...
Look at the image below:
I made a transparent sphere, and i wanted to put it in the first person character's camera, so it would fit like a helmet or something. The Player can see it when it is far from it, like in the image. But when i put the sphere in the camera, to look like a helmet, the Player doesn't have the "glass" effect. I wanted the player to actually SEE AND FEEL that his head is inside a glass bubble\helmet.
The problem is that i can't get it to work! I already reduced the clipping of the camera, but it still doesn't work. It is the same problem that occurs with water, as it is just a plane, and you can't see it when you are UNDER it. Do someone have an updated answer for this? Something that would make the player see the sphere from insidet it without changing it's appearence.
I have a Double Face script but it doesn't do anything, so i will not post it in here. I would appreciate if anyone could help me. I think Unity should make this an option, you know? Make an asset with some scripts, and one like this included. Like, something with a public variable wich you could turn ON or OFF the "see from inside".
You're on the right track with the double-face stuff. The reason you can't see the sphere from the inside is that it's made from polygons that are one-sided. The reason for it being done this way is that the engine can quickly decide to not render the polygons facing away from the camera and therefore render faster.
There's probably some haxy way to get two sides on the unity primitives, but I'd suggest building a model that's essentially just a sphere with the polygons facing inside.
Edit: I like your idea btw. Could be great with a VR camera too.
How did you create that glass effect? Is it a standard shader? A legacy shader? A random shader you found on the Internet? A material asset from the store? This would be helpful to know.
The code for disabling back culling hasn't changed at all afaik. Anyway, create a new shader or modify the one you have. Enable blending and transparency and disable back face culling. Or cull the front faces if you are only looking from the inside. Another option is to reverse the normals on the mesh.
Tags { "RenderType"="Transparent" }
Pass
{
Blend SrcAlpha One$$anonymous$$inusSrcAlpha
Cull Off
https://docs.unity3d.com/$$anonymous$$anual/SL-CullAndDepth.html
I made the glass effect by myself. I tried a lot of combinations until i found the perfect combination. I can explain to you how to make it if you want, just start a conversation with me in the forum =)
I am going to try it, hope i can make the helmet effect.
No thanks, I'm not interested in recreating the effect, I was asking so I could help you. You asked a question about a problem but didn't explain how it was being done. It's fine, there should be enough info here for you to solve.
Answer by Zitoox · Oct 01, 2016 at 11:01 PM
I made it! I used my double-face script with another one and now it is finished! Finally! My space exploration game is finally going to happen! (No, it will not be as No Man's Lie).
With my character you can now feel that you are really in a space suit. Combined with the breathing sound and some effects, the player now really feel that he is in a true space journey!
Unfortunately none of the answers were right, but i still thank you guys for trying =) I am also going to give some points to @RavenOfCode , you helped a lot ^.^
Just saying that you made it is not terribly useful to whoever comes by this question.
At first you complained you couldn't find a working solution, and this is no different: still no working solution here.
Why wouldn't you post the solution? Not only is this not an answer, it's not even the best answer in the thread.
Answer by RavenOfCode · Sep 16, 2016 at 06:38 PM
Your gonna want to make a sphere with the normals inverted. The normals are the direction of the quads on your object. To see them the normal must be pointed at you, if you flip them you can flip the object and still see the sphere. If you have blender you can invert a sphere quite simply (if you don't its free so you should get it, it can do almost anything). Go into edit mode (tab) > select all faces (a) (make sure they all light up, you may have to press this a few times) > press w > then select flip normals. And boom your good.
If you don't have blender and want to do it in Unity there are a few ways of doing it. You can use a script to create a sphere with inverted normals, something like this. Or you could turn off culling (its recommended you don't as it is a huge performance hit) but it will render both sides, if you want to do this then go ahead, it should be your last resort though.
If you have any questions feel free to ask. Hope this helps!
Still, nothing, nothing changed with the script. When i approach the sphere to the player, automatically when the sphere enters in the camera's area, it simply disappear.
Do you know how do i turn off culling? I want to test it. Probaly it will not change almost anything, the game doesn't focus on having much details, so i am pretty sure that it will not change more than a few fps. Unless it turns 60fps to 10fps when you turn it off, i am pretty sure this is the best option.
Did you try making a sphere with inverted normals in blender? That is the easiest way.
If you want to look into culling you need a shader with Cull Off, or Cull Front to flip what is rendered. Cull basically means what not to render, Cull Back is default. After looking into this more Cull Front is a great way to do this, there should be no performance hit as the same amount of stuff is getting rendered.
Here is the manual on it.
Answer by Casiell · Feb 21, 2018 at 10:22 AM
Seeing as this question is the first link you find in google I figured I would post a solution.
Just add this script to the object you want to see from the inside. It reverses normals of the mesh on Start so you have to press "Play" to see the effect. The side effect is that you don't see the object from the outside now, but if you need that just duplicate your object and place it in the same spot.
Answer by Honorsoft · Jun 20, 2018 at 08:07 PM
Instead of flipping normal back and forth, you can simply give the object (that you want to be visible from the inside) a shader with culling turned off. I have seen no 'performance hit'. You can add "Cull Off" to the sub-shader section of any shader, here is the Standard Shader with Cull Off, it should work with Unity 5, but doesn't seem to compile with Unity 2018: //Save as StandardCullOFF.shader Shader "StandardCullOFF" { Properties { _Color("Color", Color) = (1,1,1,1) _MainTex("Albedo", 2D) = "white" {}
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
_Glossiness("Smoothness", Range(0.0, 1.0)) = 0.5
_GlossMapScale("Smoothness Scale", Range(0.0, 1.0)) = 1.0
[Enum(Metallic Alpha,0,Albedo Alpha,1)] _SmoothnessTextureChannel ("Smoothness texture channel", Float) = 0
[Gamma] _Metallic("Metallic", Range(0.0, 1.0)) = 0.0
_MetallicGlossMap("Metallic", 2D) = "white" {}
[ToggleOff] _SpecularHighlights("Specular Highlights", Float) = 1.0
[ToggleOff] _GlossyReflections("Glossy Reflections", Float) = 1.0
_BumpScale("Scale", Float) = 1.0
_BumpMap("Normal Map", 2D) = "bump" {}
_Parallax ("Height Scale", Range (0.005, 0.08)) = 0.02
_ParallaxMap ("Height Map", 2D) = "black" {}
_OcclusionStrength("Strength", Range(0.0, 1.0)) = 1.0
_OcclusionMap("Occlusion", 2D) = "white" {}
_EmissionColor("Color", Color) = (0,0,0)
_EmissionMap("Emission", 2D) = "white" {}
_DetailMask("Detail Mask", 2D) = "white" {}
_DetailAlbedoMap("Detail Albedo x2", 2D) = "grey" {}
_DetailNormalMapScale("Scale", Float) = 1.0
_DetailNormalMap("Normal Map", 2D) = "bump" {}
[Enum(UV0,0,UV1,1)] _UVSec ("UV Set for secondary textures", Float) = 0
// Blending state
_Mode ("__mode", Float) = 0.0
_SrcBlend ("__src", Float) = 1.0
_DstBlend ("__dst", Float) = 0.0
_ZWrite ("__zw", Float) = 1.0
}
CGINCLUDE
#define UNITY_SETUP_BRDF_INPUT MetallicSetup
ENDCG
SubShader
{
Tags { "RenderType"="Opaque" "PerformanceChecks"="False" }
LOD 300
// ------------------------------------------------------------------
// Base forward pass (directional light, emission, lightmaps, ...)
Pass
{
Name "FORWARD"
Tags { "LightMode" = "ForwardBase" }
Blend [_SrcBlend] [_DstBlend]
ZWrite [_ZWrite]
Cull Off
CGPROGRAM
#pragma target 3.0
// -------------------------------------
#pragma shader_feature _NORMALMAP
#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
#pragma shader_feature _EMISSION
#pragma shader_feature _METALLICGLOSSMAP
#pragma shader_feature ___ _DETAIL_MULX2
#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF
#pragma shader_feature _ _GLOSSYREFLECTIONS_OFF
#pragma shader_feature _PARALLAXMAP
#pragma multi_compile_fwdbase
#pragma multi_compile_fog
#pragma vertex vertBase
#pragma fragment fragBase
#include "UnityStandardCoreForward.cginc"
ENDCG
}
// ------------------------------------------------------------------
// Additive forward pass (one light per pass)
Pass
{
Name "FORWARD_DELTA"
Tags { "LightMode" = "ForwardAdd" }
Blend [_SrcBlend] One
Fog { Color (0,0,0,0) } // in additive pass fog should be black
ZWrite Off
ZTest LEqual
CGPROGRAM
#pragma target 3.0
// -------------------------------------
#pragma shader_feature _NORMALMAP
#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
#pragma shader_feature _METALLICGLOSSMAP
#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF
#pragma shader_feature ___ _DETAIL_MULX2
#pragma shader_feature _PARALLAXMAP
#pragma multi_compile_fwdadd_fullshadows
#pragma multi_compile_fog
#pragma vertex vertAdd
#pragma fragment fragAdd
#include "UnityStandardCoreForward.cginc"
ENDCG
}
// ------------------------------------------------------------------
// Shadow rendering pass
Pass {
Name "ShadowCaster"
Tags { "LightMode" = "ShadowCaster" }
ZWrite On ZTest LEqual
CGPROGRAM
#pragma target 3.0
// -------------------------------------
#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
#pragma shader_feature _METALLICGLOSSMAP
#pragma shader_feature _PARALLAXMAP
#pragma multi_compile_shadowcaster
#pragma vertex vertShadowCaster
#pragma fragment fragShadowCaster
#include "UnityStandardShadow.cginc"
ENDCG
}
// ------------------------------------------------------------------
// Deferred pass
Pass
{
Name "DEFERRED"
Tags { "LightMode" = "Deferred" }
CGPROGRAM
#pragma target 3.0
#pragma exclude_renderers nomrt
// -------------------------------------
#pragma shader_feature _NORMALMAP
#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
#pragma shader_feature _EMISSION
#pragma shader_feature _METALLICGLOSSMAP
#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF
#pragma shader_feature ___ _DETAIL_MULX2
#pragma shader_feature _PARALLAXMAP
#pragma multi_compile ___ UNITY_HDR_ON
#pragma multi_compile ___ LIGHTMAP_ON
#pragma multi_compile ___ DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE
#pragma multi_compile ___ DYNAMICLIGHTMAP_ON
#pragma vertex vertDeferred
#pragma fragment fragDeferred
#include "UnityStandardCore.cginc"
ENDCG
}
// ------------------------------------------------------------------
// Extracts information for lightmapping, GI (emission, albedo, ...)
// This pass it not used during regular rendering.
Pass
{
Name "META"
Tags { "LightMode"="Meta" }
Cull Off
CGPROGRAM
#pragma vertex vert_meta
#pragma fragment frag_meta
#pragma shader_feature _EMISSION
#pragma shader_feature _METALLICGLOSSMAP
#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#pragma shader_feature ___ _DETAIL_MULX2
#include "UnityStandardMeta.cginc"
ENDCG
}
}
SubShader
{
Tags { "RenderType"="Opaque" "PerformanceChecks"="False" }
LOD 150
// ------------------------------------------------------------------
// Base forward pass (directional light, emission, lightmaps, ...)
Pass
{
Name "FORWARD"
Tags { "LightMode" = "ForwardBase" }
Blend [_SrcBlend] [_DstBlend]
ZWrite [_ZWrite]
CGPROGRAM
#pragma target 2.0
#pragma shader_feature _NORMALMAP
#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
#pragma shader_feature _EMISSION
#pragma shader_feature _METALLICGLOSSMAP
#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF
#pragma shader_feature _ _GLOSSYREFLECTIONS_OFF
// SM2.0: NOT SUPPORTED shader_feature ___ _DETAIL_MULX2
// SM2.0: NOT SUPPORTED shader_feature _PARALLAXMAP
#pragma skip_variants SHADOWS_SOFT DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE
#pragma multi_compile_fwdbase
#pragma multi_compile_fog
#pragma vertex vertBase
#pragma fragment fragBase
#include "UnityStandardCoreForward.cginc"
ENDCG
}
// ------------------------------------------------------------------
// Additive forward pass (one light per pass)
Pass
{
Name "FORWARD_DELTA"
Tags { "LightMode" = "ForwardAdd" }
Blend [_SrcBlend] One
Fog { Color (0,0,0,0) } // in additive pass fog should be black
ZWrite Off
ZTest LEqual
CGPROGRAM
#pragma target 2.0
#pragma shader_feature _NORMALMAP
#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
#pragma shader_feature _METALLICGLOSSMAP
#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF
#pragma shader_feature ___ _DETAIL_MULX2
// SM2.0: NOT SUPPORTED shader_feature _PARALLAXMAP
#pragma skip_variants SHADOWS_SOFT
#pragma multi_compile_fwdadd_fullshadows
#pragma multi_compile_fog
#pragma vertex vertAdd
#pragma fragment fragAdd
#include "UnityStandardCoreForward.cginc"
ENDCG
}
// ------------------------------------------------------------------
// Shadow rendering pass
Pass {
Name "ShadowCaster"
Tags { "LightMode" = "ShadowCaster" }
ZWrite On ZTest LEqual
CGPROGRAM
#pragma target 2.0
#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
#pragma shader_feature _METALLICGLOSSMAP
#pragma skip_variants SHADOWS_SOFT
#pragma multi_compile_shadowcaster
#pragma vertex vertShadowCaster
#pragma fragment fragShadowCaster
#include "UnityStandardShadow.cginc"
ENDCG
}
// ------------------------------------------------------------------
// Extracts information for lightmapping, GI (emission, albedo, ...)
// This pass it not used during regular rendering.
Pass
{
Name "META"
Tags { "LightMode"="Meta" }
Cull Off
CGPROGRAM
#pragma vertex vert_meta
#pragma fragment frag_meta
#pragma shader_feature _EMISSION
#pragma shader_feature _METALLICGLOSSMAP
#pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
#pragma shader_feature ___ _DETAIL_MULX2
#include "UnityStandardMeta.cginc"
ENDCG
}
}
FallBack "VertexLit"
CustomEditor "StandardShaderGUI"
}
Your answer
Follow this Question
Related Questions
Random insideUnitSphere but outside other UnitSphere? 2 Answers
Flip normals 0 Answers
Random spawn script 1 Answer
Procedural sphere defects 1 Answer