Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 janzdott · May 03, 2013 at 05:36 PM · shadereditorwarningstrumpy

Help Fixing Warnings in this Shader?

Hey everyone. I don't know anything about writing shaders. I used Strumpy Shader Editor to make this shader, and it's giving me a bunch of warnings. I'm using Unity 4.0.0f7. This shader is meant to blend 3 different textures based on the vertex colors of the mesh. The shader works, but gives me warnings. Here's the shader code.

 Shader "VertexColorTextureBlend" {
     Properties {
         _Texture1("_Texture1", 2D) = "black" {}
         _Texture2("_Texture2", 2D) = "black" {}
         _Texture3("_Texture3", 2D) = "black" {}
     }    
     SubShader {
         Tags {
             "Queue"="Geometry"
             "IgnoreProjector"="False"
             "RenderType"="Opaque"
         }        
         Cull Back
         ZWrite On
         ZTest LEqual
         ColorMask RGBA
         Fog {}
 
         CGPROGRAM
         #pragma surface surf BlinnPhongEditor  vertex:vert
         #pragma target 2.0
 
         sampler2D _Texture1;
         sampler2D _Texture2;
         sampler2D _Texture3;
 
         struct EditorSurfaceOutput {
             half3 Albedo;
             half3 Normal;
             half3 Emission;
             half3 Gloss;
             half Specular;
             half Alpha;
             half4 Custom;
         };
             
         inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light) {
             half3 spec = light.a * s.Gloss;
             half4 c;
             c.rgb = (s.Albedo * light.rgb + light.rgb * spec);
             c.a = s.Alpha;
             return c;
         }
 
         inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten) {
             half3 h = normalize (lightDir + viewDir);
                 
             half diff = max (0, dot ( lightDir, s.Normal ));
                 
             float nh = max (0, dot (s.Normal, h));
             float spec = pow (nh, s.Specular*128.0);
                 
             half4 res;
             res.rgb = _LightColor0.rgb * diff;
             res.w = spec * Luminance (_LightColor0.rgb);
             res *= atten * 2.0;
 
             return LightingBlinnPhongEditor_PrePass( s, res );
         }
 
         inline half4 LightingBlinnPhongEditor_DirLightmap (EditorSurfaceOutput s, fixed4 color, fixed4 scale, half3 viewDir, bool surfFuncWritesNormal, out half3 specColor) {
             UNITY_DIRBASIS
             half3 scalePerBasisVector;
                 
             half3 lm = DirLightmapDiffuse (unity_DirBasis, color, scale, s.Normal, surfFuncWritesNormal, scalePerBasisVector);
                 
             half3 lightDir = normalize (scalePerBasisVector.x * unity_DirBasis[0] + scalePerBasisVector.y * unity_DirBasis[1] + scalePerBasisVector.z * unity_DirBasis[2]);
             half3 h = normalize (lightDir + viewDir);
             
             float nh = max (0, dot (s.Normal, h));
             float spec = pow (nh, s.Specular * 128.0);
                 
             // specColor used outside in the forward path, compiled out in prepass
             specColor = lm * _SpecColor.rgb * s.Gloss * spec;
                 
             // spec from the alpha component is used to calculate specular
             // in the Lighting*_Prepass function, it's not used in forward
             return half4(lm, spec);
         }
             
         struct Input {
             float2 uv_Texture1;
             float4 color : COLOR;
             float2 uv_Texture2;
             float2 uv_Texture3;
         };
 
         void vert (inout appdata_full v, out Input o) {
             float4 VertexOutputMaster0_0_NoInput = float4(0,0,0,0);
             float4 VertexOutputMaster0_1_NoInput = float4(0,0,0,0);
             float4 VertexOutputMaster0_2_NoInput = float4(0,0,0,0);
             float4 VertexOutputMaster0_3_NoInput = float4(0,0,0,0);
         }            
 
         void surf (Input IN, inout EditorSurfaceOutput o) {
             o.Normal = float3(0.0,0.0,1.0);
             o.Alpha = 1.0;
             o.Albedo = 0.0;
             o.Emission = 0.0;
             o.Gloss = 0.0;
             o.Specular = 0.0;
             o.Custom = 0.0;
                 
             float4 Sampled2D0=tex2D(_Texture1,IN.uv_Texture1.xy);
             float4 Split0=IN.color;
             float4 Lerp0=lerp(float4( 0,0,0,0),Sampled2D0,float4( Split0.x, Split0.x, Split0.x, Split0.x));
             float4 Sampled2D1=tex2D(_Texture2,IN.uv_Texture2.xy);
             float4 Lerp1=lerp(float4( 0,0,0,0),Sampled2D1,float4( Split0.y, Split0.y, Split0.y, Split0.y));
             float4 Add0=Lerp0 + Lerp1;
             float4 Sampled2D2=tex2D(_Texture3,IN.uv_Texture3.xy);
             float4 Lerp2=lerp(float4( 0,0,0,0),Sampled2D2,float4( Split0.z, Split0.z, Split0.z, Split0.z));
             float4 Add1=Add0 + Lerp2;
             float4 Master0_1_NoInput = float4(0,0,1,1);
             float4 Master0_2_NoInput = float4(0,0,0,0);
             float4 Master0_3_NoInput = float4(0,0,0,0);
             float4 Master0_4_NoInput = float4(0,0,0,0);
             float4 Master0_5_NoInput = float4(1,1,1,1);
             float4 Master0_7_NoInput = float4(0,0,0,0);
             float4 Master0_6_NoInput = float4(1,1,1,1);
             o.Albedo = Add1;
 
             o.Normal = normalize(o.Normal);
         }
         ENDCG
     }
     Fallback "Diffuse"
 }


And these are the warnings I'm getting...

Shader warning in 'VertexColorTextureBlend': Program 'vert_surf', implicit truncation of vector type (compiling for d3d11) at line 17

Shader warning in 'VertexColorTextureBlend': Program 'vert_surf', implicit truncation of vector type (compiling for d3d11_9x) at line 17

Shader warning in 'VertexColorTextureBlend': Program 'vert_surf', 'vert': output parameter 'o' not completely initialized (compiling for d3d11) at line 87

Shader warning in 'VertexColorTextureBlend': Program 'vert_surf', 'vert': output parameter 'o' not completely initialized (compiling for d3d11_9x) at line 87

Can anyone tell me how to fix this? I would really appreciate some help

Comment
Add comment · Show 4
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 janzdott · May 03, 2013 at 06:28 PM 1
Share

I added this line, which got rid of the warnings

 #pragma exclude_renderers d3d11 d3d11_9x

Is this okay? Or would it be better to actually fix what it's complaining about?

avatar image landon912 · May 03, 2013 at 08:56 PM 0
Share

It's fine for a quick fix to get rid of the annoying updates in the log. In time you should fix them completely.

avatar image whydoidoit · May 03, 2013 at 09:47 PM 0
Share

If you need to run on DirectX you should fix them. I've no idea what'd going on with that shader though - what on earth are all the $$anonymous$$aster0_1_NoInputs about - doing nothing except taking time. You'd need to look at the compiled shader to properly spot what's going on I think. It's probably just complaining about implicitly changing floats to halfs or something. And the vertex program vert is another totally useless thing that sets none of the output variables and just wastes a bit of time.

avatar image janzdott · May 04, 2013 at 10:42 PM 0
Share

Yeah I'd love if someone could help me get rid of those errors, and maybe optimize this. Like I said, I know nothing about writing shaders. This was made in Strumpy Shader Editor. But this is for the terrain on my Android game, so it would help if the shader was a bit more optimized.

2 Replies

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

Answer by janzdott · May 04, 2013 at 11:42 PM

Well I looked at the Unity docs for a little bit, and I'm starting to understand shaders now. I shortened it down to this. The errors are gone. And it's probably faster too :)

 Shader "VertexColorTextureBlend" {
     Properties {
         _Texture1("_Texture1", 2D) = "black" {}
         _Texture2("_Texture2", 2D) = "black" {}
         _Texture3("_Texture3", 2D) = "black" {}
     }    
     SubShader {        
         CGPROGRAM
         #pragma surface surf Lambert
         #pragma target 2.0
 
         sampler2D _Texture1;
         sampler2D _Texture2;
         sampler2D _Texture3;
             
         struct Input {
             float2 uv_Texture1;
             float2 uv_Texture2;
             float2 uv_Texture3;
             float4 color : COLOR;
         };            
 
         void surf (Input IN, inout SurfaceOutput o) {                
             float4 red = lerp(float4(0, 0, 0, 0), tex2D(_Texture1, IN.uv_Texture1.xy), float4(IN.color.x, IN.color.x, IN.color.x, IN.color.x));
             float4 green = lerp(float4(0, 0, 0, 0), tex2D(_Texture2, IN.uv_Texture2.xy), float4(IN.color.y, IN.color.y, IN.color.y, IN.color.y));
             float4 blue = lerp(float4(0, 0, 0, 0), tex2D(_Texture3, IN.uv_Texture3.xy), float4(IN.color.z, IN.color.z, IN.color.z, IN.color.z));
             o.Albedo = red + green + blue;
         }
         ENDCG
     }
     Fallback "Diffuse"
 }

Is there any further optimizing I can do? Since this is for Android, it needs to be fast as possible

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
avatar image
0

Answer by defaxer · Apr 03, 2014 at 12:05 PM

Try replacing:

 void surf (Input IN, inout SurfaceOutput o) {          
          float4 red = lerp(float4(0, 0, 0, 0), tex2D(_Texture1, IN.uv_Texture1.xy), float4(IN.color.x, IN.color.x, IN.color.x, IN.color.x));
          float4 green = lerp(float4(0, 0, 0, 0), tex2D(_Texture2, IN.uv_Texture2.xy), float4(IN.color.y, IN.color.y, IN.color.y, IN.color.y));
          float4 blue = lerp(float4(0, 0, 0, 0), tex2D(_Texture3, IN.uv_Texture3.xy), float4(IN.color.z, IN.color.z, IN.color.z, IN.color.z));
          o.Albedo = red + green + blue;
        }

with:

 void surf (Input IN, inout SurfaceOutput o) {
          fixed4 c;
          c = tex2D(_Texture1, IN.uv_Texture1.xy) * IN.color.x;
          c += tex2D(_Texture2, IN.uv_Texture2.xy) * IN.color.y;
          c += tex2D(_Texture3, IN.uv_Texture3.xy) * IN.color.z;
          o.Albedo = c;
        }

though I cant say it's super fast now :)

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.

Follow this Question

Answers Answers and Comments

16 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

Related Questions

Strumpy shaders... Y U NO dynamic batch ?? 0 Answers

Shader Errors Strumpy Shader Editor 2 Answers

Strumpy Shader working in editor but not in build. 0 Answers

2sided Shader - Strumpy Shader Editor 1 Answer

Strumpy Parallax Shader 2 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