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 Reverend-Speed · Jul 18, 2018 at 10:36 AM · shadershader programmingfogclouds

Why is my scrolling shader suddenly rendering as magenta? (May be related to fog)

Hey folks. Was writing a vfx shader which can be seen in action here. After the version seen in the webplayer, I added a new skybox, particles and fog. Everything seemed to be working well, until I reloaded the project later and the shader was rendering as magenta, with the following errors:

  • Shader error in 'PF/CloudScroll01': Duplicated input semantics can't change type, size, or layout ('TEXCOORD1'). at line 44 (on d3d11)

  • Shader error in 'PF/CloudScroll01': output TEXCOORD1 used more than once at line 44 (on d3d11)

  • Shader warning in 'PF/CloudScroll01': Duplicate non-system value semantic definition: output semantic 'TEXCOORD1' and output semantic 'TEXCOORD1' at line 43 (on d3d11)

  • Shader warning in 'PF/CloudScroll01': Duplicate non-system value semantic definition: output semantic 'TEXCOORD1' and output semantic 'TEXCOORD1' at line 44 (on d3d11)

Removing all references to fog (UNITY_FOG_COORDS(1) in struct v2f, UNITY_TRANSFER_FOG in v2f vert, UNITY_APPLY_FOG in fixed4 frag) makes the sky render 'correctly' again, but I'd like to experiment with how it interacts with fog (given the nature of the effect).

Can anybody help me get the effect working with fog and NOT rendering as magenta? Shader code follows...

 Shader "PF/CloudScroll01"
 {
     Properties
     {
         _MainTex    ("Texture", 2D) = "white" {}
         _MaskTex    ("Mask Texture", 2D) = "white" {}
         _ScrollXSpeed("Scroll X Speed", float) = 1
         _ScrollYSpeed("Scroll Y Speed", float) = 1
         _MaskMul    ("Mask Multiplier", float) = 1
         _AlphMul    ("Alpha Multiplier", float) = 1
 
         _CloudCol    ("Colour", Color) = (0,0,0,0)
     }
     SubShader
     {
         Tags { "Queue"="Transparent" "RenderType"="Transparent" "IgnoreProjector"="True"}
         LOD 100
         zwrite off
         Blend SrcAlpha OneMinusSrcAlpha // Makes it transparent?
 
         Pass
         {
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             // make fog work
             #pragma multi_compile_fog
             
             
             #include "UnityCG.cginc"
 
             struct appdata_f
             {
                 float4 vertex : POSITION;
                 float2 texcoord0 : TEXCOORD0;
                 float2 texcoord1 : TEXCOORD1; // Getting second set of UV coords.
             };
 
             struct v2f
             {
                 float4 vertex : SV_POSITION; // Final vertex positions in clip space (view frustrum)
                 float2 texcoord0  : TEXCOORD0; // Presumbably this is where the UV data gets acquired?
                 float2 texcoord1 : TEXCOORD1;
                 UNITY_FOG_COORDS(1)
                 UNITY_VERTEX_OUTPUT_STEREO
             };
 
             sampler2D _MainTex;
             float4 _MainTex_ST; // for any tex property, Unity provides val for float4 w/"_ST" suffix. The x,y contains texture scale, and z,w contains translation (offset).
             sampler2D _MaskTex;
             float4 _MaskTex_ST;
 
             float _ScrollXSpeed;
             float _ScrollYSpeed;
 
             float _MaskMul;
             float _AlphMul;
 
             fixed4 _CloudCol;
             
             v2f vert (appdata_f v)
             {
                 v2f o;
                 v.texcoord0.y += _Time * _ScrollYSpeed;
                 v.texcoord0.x += _Time * _ScrollXSpeed;
                 o.vertex = UnityObjectToClipPos(v.vertex);
                 o.texcoord0 = TRANSFORM_TEX(v.texcoord0, _MainTex);
                 o.texcoord1 = TRANSFORM_TEX(v.texcoord1, _MaskTex);
                 UNITY_TRANSFER_FOG(o,o.vertex);
                 return o;
             }
             
             // Fragments - pre'pixels'.
             fixed4 frag (v2f i) : SV_Target
             {
                 // sample the texture
                 fixed4 col01 = tex2D(_MainTex, i.texcoord0);
                 // col01.rgb = dot(col01.rgb, _CloudCol.rgb);
                 fixed4 col02 = tex2D(_MaskTex, i.texcoord1);
                 fixed4 colOut = fixed4(col01.r, col01.b, col01.g, (col01.a * _AlphMul) * (col02.a * _MaskMul));
                 // apply fog
                 UNITY_APPLY_FOG(i.fogCoord, colOut);
                 return colOut;
             }
             ENDCG
         }
     }
 }

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
3
Best Answer

Answer by BastianUrbach · Jul 18, 2018 at 03:46 PM

If I remember it correctly, the parameter of UNITY_FOG_COORDS(1) tells Unity which texcoord semantic should be used for fog. So replacing that line with UNITY_FOG_COORDS(2) should fix it.

Comment
Add comment · Show 2 · 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
avatar image Reverend-Speed · Jul 21, 2018 at 09:52 PM 0
Share

Absolutely perfect, bang on, thank you for setting me straight. Don't suppose you know how many UNITY_FOG_COORDS there are, or what they do? (Or have a link to that info? Can't find one...!) Either way, many thanks!

avatar image laurentlavigne · May 23, 2020 at 03:09 AM 0
Share

If you run for president I vote for you.

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

138 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

Related Questions

Why is global fog not affecting an object with shader made with ShaderGraph? 0 Answers

Unlit Transparent With Color Support 1 Answer

create a texture with shader code? ( without using a texture ) 1 Answer

How to add Emission to my custom shader? 2 Answers

The Best Way To Make Stylised Grass in Unity? 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