• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Willard720 · Dec 09, 2018 at 04:42 AM · lightingshadersshadowstoonshadingtoon shader

How to stop shadows on shader from depending on camera angle

EDIT:

So I found out that the error was coming from the fact that ToonShader gets it's toony effect by using an image in the cube map slot, which is where reflection data is supposed to go, reflection data being dependent on camera angle. This seems like a bad way to do it. Any other better ways?

My shader:

 Shader "Toon/Basic" 
 {
     Properties 
     {
         _Color ("Main Color", Color) = (0.5, 0.5, 0.5, 1)
         _MainTex ("Base (RGB)", 2D)  = "white" { }
         _ToonShade ("ToonShader Cubemap(RGB)", CUBE) = "" { }
     }
     SubShader 
     {
         Tags { "LightMode" = "ForwardBase" }
         Pass 
         {
             Name "BASE"
             Cull Off
         
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             #pragma multi_compile_fog
             #include "UnityCG.cginc"

             samplerCUBE _ToonShade;
             sampler2D _MainTex;
             float4 _MainTex_ST;
             float4 _Color;

             struct appdata 
             {
                 float4 vertex   : POSITION;
                 float2 texcoord : TEXCOORD0;
                 float3 normal   : NORMAL;
                 fixed4 col      : COLOR0;
             };
             struct v2f 
             {
                 float4 pos        : SV_POSITION;
                 float2 texcoord   : TEXCOORD0;
                 float3 cubenormal : TEXCOORD1;

                 UNITY_FOG_COORDS(2)
             };
             v2f vert (appdata v)
             {
                 v2f o;

                 o.pos        = UnityObjectToClipPos(v.vertex);
                 o.texcoord   = TRANSFORM_TEX(v.texcoord, _MainTex);
                 o.cubenormal = mul (UNITY_MATRIX_MV - 0.2, float4(v.normal, 0));

                 UNITY_TRANSFER_FOG(o, o.pos);
             
                 return o;
             }
             fixed4 frag (v2f i) : SV_Target
             {
                 fixed4 col  = _Color * tex2D(_MainTex, i.texcoord);
                 fixed4 cube = texCUBE(_ToonShade, i.cubenormal);
                 fixed4 c    = fixed4(2.0f * cube.rgb * col.rgb, col.a);
                 UNITY_APPLY_FOG(i.fogCoord, c);
             
                 return c;
             }
             ENDCG            
         }
     } 

     Fallback "VertexLit"
 }

This is a modified version of the ToonBasic script. The issue I'm having is that when the camera angle changes so do all the shadows and highlights using this shader.

It's incredibly unrealistic and looks horrible especially when going over hills. I can't see anything in here that involves camera angles so I'm really stuck. I have no idea about shaders, I work in C# not whatever language this is so I have no idea how to solve this.

Any ideas?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Willard720 · Dec 09, 2018 at 11:04 PM

Found the answer. Because they were using a reflection for that effect, it depending on the camera angle. So I found this shader instead.


It doesn't change on the camera angle, and I can choose how many levels I want.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

196 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Shadows work on a scene but not on another scene. Is driving me nuts. 0 Answers

Receive Shadow Mesh Renderer - Weird Effect 0 Answers

How to adjust self-shadows 1 Answer

Remove circular shadow from object 1 Answer

Fake Directional Lighting 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges