Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 /
avatar image
0
Question by Jayckob · Feb 26, 2017 at 01:03 PM · shaderdistance

shader distance returns larger value further from 0,0,0

alt text

So this is the origin, 0,0,0 , and the shader I have makes stuff in the background slightly blue:

 Shader "Unlit/Diffuse" {
      Properties
      {
          _Color ("Main Color", Color) = (1,1,1,1)
          _MainTexture ("Main Texture", 2D) = "white" {}
      }
      SubShader {
          
          Pass {  
              CGPROGRAM
                  #pragma vertex vert
                  #pragma fragment frag
 
                  #pragma "UnityCG.cginc"
      
                  struct appdata {
                      float4 vertex : POSITION;
                      float3 normal : NORMAL;
                      float2 texcoord : TEXCOORD0;
                  };
      
                  struct v2f {
                      float4 pos : SV_POSITION;
                      float3 normal : NORMAL;
                      float2 texcoord : TEXCOORD0;
                  };
 
                  float4 _LightColor0;
 
                  //float4x4 _Object2World;
                  fixed4 _Color;
                  sampler2D _MainTexture;
                  float dist;
                  
                  v2f vert (appdata IN)
                  {
                      v2f OUT;
                      OUT.pos = mul(UNITY_MATRIX_MVP, IN.vertex);
                      OUT.normal = mul(float4(IN.normal, 0.0), _Object2World).xyz;
                      OUT.texcoord = IN.texcoord;
                      return OUT;
                  }
                  
                  fixed4 frag (v2f IN) : COLOR
                  {
                      float3 normalDirection = normalize(IN.normal);
                      float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
                      float3 diffuse = _LightColor0.rgb * max(0.0, dot(lightDirection, normalDirection) * -1);
 
                      dist = distance(_WorldSpaceCameraPos, mul(_Object2World, IN.pos).xyz);
                      fixed4 texColor = tex2D(_MainTexture, IN.texcoord);
                          
                     return lerp(texColor,fixed4(0,0.7,1,1), (dist/10000000));
                  }
              ENDCG
          }
      }
  }

The problem is when I walk about 3000 units in any direction the blue becomes very intense:

alt text

So why is the distance not working like it should? Also the few chunks around the origin (0,0,0) are green no matter how far they are from the camera, shouldn't the shader make distant pixels blue?

I'm lost here and don't know what is making this happpen.

screenshot-7-4.png (227.2 kB)
screenshot-9-3.png (225.6 kB)
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

0 Replies

· Add your reply
  • Sort: 

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.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Classic Game Distance masking darkness/fog help 1 Answer

Objects surface look grey/foggy at distance 1 Answer

Transparent Cutout Shader - max transparency distance? 1 Answer

How to force the compilation of a shader in Unity? 5 Answers

Shader distance between WorldSpaceCameraPos and Vertex 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges