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 Paul-van-der-Laan · Jan 05, 2016 at 08:55 AM · shadervertexcgfragmentsnow

Unexpected behavior in Vertex/Fragment shader when using saturate method (CG)

Im learning shader writing lately and now im trying to write a simple snow shader which blends 2 textures based on the snowdirection. At the moment, the snowmask looks like i want it to (black and white mask in unity viewport), but when i apply a saturation method to it, it seems all pure black pixels in the shadows turn white. I dont understand why because in my understanding, the saturation method should not make dark pixels (<= 0) to white (1). What is happening?

 Shader "Simple Snow Shader2" 
 {
 
     Properties
     {
         _MainTex("Base (RGB)", 2D) = "white" {}
         _SnowDirection("Snow Direction", Vector) = (0,1,0)
         _SnowFalloff("Snow Falloff", float) = 1.0
         _SnowTiling("Snow Tiling", float) = 1.0
     }
 
     SubShader
     {
         Pass
         {
             CGPROGRAM
             #pragma vertex vert  
             #pragma fragment frag 
             #include "UnityCG.cginc"
 
             sampler2D _MainTex;
             float4 _SnowDirection;
             float _SnowFalloff;
             float _SnowTiling;
         
 
             struct vertexInput 
             {
                 float4 vertex : POSITION;
                 float4 tangent : TANGENT;
                 float4 uv : TEXCOORD0;
                 float3 normal : NORMAL;
                 fixed4 color : COLOR;
             };
     
             struct vertexOutput 
             {
                 float4 pos : SV_POSITION;
                 float4 col : TEXCOORD0;
                 float4 worldnormal : NORMAL;
                 float2 uv : TEXCOORD1;
             };
 
             vertexOutput vert(vertexInput input)
             {
                 vertexOutput output;
                 output.pos = mul(UNITY_MATRIX_MVP, input.vertex);
                 float4 worldnormal = mul(_Object2World, float4(input.normal, 0.0));
                 output.worldnormal = worldnormal;
                 output.col = input.color;
                 return output;
             }
 
             float4 frag(vertexOutput input) : COLOR
             {
         
                 float4 diffuse = tex2D(_MainTex, input.uv);
                 float4 snowmask = pow(dot(input.worldnormal, _SnowDirection), _SnowFalloff);
                 //input.col = saturate(snowmask);
                 input.col = (snowmask);
 
                 return input.col;
             }
 
             ENDCG
         }
     }
 }
Comment
Add comment · Show 1
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
avatar image Paul-van-der-Laan · Jan 04, 2016 at 10:15 PM 0
Share

I think i found it. In this line:

float4 snowmask = pow(dot(input.worldnormal, _SnowDirection), _SnowFalloff

the dot product gives a range of -1 to 1 while the power function makes all negative values positive. I guess that's the reason i get white results in the shadow areas.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Prevent ColorMask obscuring parts of an object's mesh 0 Answers

Stop shader values from being clamped 1 Answer

Refraction Shader. Strange Artifacts 0 Answers

Why doesn't this vertex+fragment shader work? 0 Answers

Blend textures in shader 0 Answers


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