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 /
This question was closed Apr 04, 2017 at 09:16 AM by Bladynator for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Bladynator · Apr 03, 2017 at 03:27 PM · errorshader

(FIXED) Shader Error due to dynamic conditional 'if' blocks

FIX: Disabled D3D9 support.

I searched online and could find some similar problems, but none of them fixed my problem. It is an error that ONLY occurs when building the game. When playing from the editor no errors are seen and the shader works as intended.

The error:

Shader error in 'Custom/Outline_2DSprite': texld/texldb/texldp/dsx/dsy instructions with r# as source cannot be used inside dynamic conditional 'if' blocks, dynamic conditional subroutine calls, or loop/rep with break*. at line 35 (on d3d9)

The important bit of the shader:

 CGPROGRAM
            #pragma surface surf Lambert alpha
     
            struct Input 
            {
                float2 uv_MainTex;
                fixed4 color : COLOR;
            };
     
            sampler2D _MainTex;
            float _OutLineSpreadX;
            float _OutLineSpreadY;
            float4 _Color;
     
            void surf(Input IN, inout SurfaceOutput o)
            {
                 fixed4 tex1 = tex2D(_MainTex, IN.uv_MainTex+float2(_OutLineSpreadX,0.0));
                 fixed4 tex2 = tex2D(_MainTex, IN.uv_MainTex-float2(_OutLineSpreadX,0.0));
                 fixed4 tex3 = tex2D(_MainTex, IN.uv_MainTex+float2(0.0,_OutLineSpreadY));
                 fixed4 tex4 = tex2D(_MainTex, IN.uv_MainTex-float2(0.0,_OutLineSpreadY));
                fixed4 TempColor = tex1 + tex2;
                TempColor = TempColor + tex3 + tex4;
                if(TempColor.a > 0.1){
                    TempColor.a = 1;
                }
                   fixed4 AlphaColor = fixed4(TempColor.a,TempColor.a,TempColor.a,TempColor.a);
                fixed4 mainColor = AlphaColor * _Color.rgba;
                fixed4 addcolor = tex2D(_MainTex, IN.uv_MainTex) * IN.color;
     
                if(addcolor.a > 0.95){
                    mainColor = addcolor;
                }
     
                o.Albedo = mainColor.rgb;
                o.Alpha = mainColor.a;
            }
            ENDCG

It has to do with the fact that I can't use tex2D inside an if statement, but can't seem to fix it.

Comment
Add comment · Show 6
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 meat5000 ♦ · Apr 03, 2017 at 03:33 PM 0
Share

Post the whole shader. It might be the important bit for the effect you want but as far as bugs are concerned importance is a different matter :)

avatar image Bladynator meat5000 ♦ · Apr 03, 2017 at 03:39 PM 0
Share

Since editing the code part is a bit wonky? I put the whole shader down here:

 Shader "Custom/Outline_2DSprite"
     {
         Properties 
            {
                _$$anonymous$$ainTex ("Base (RGB)", 2D) = "white" {}
                _OutLineSpreadX ("Outline Spread", Range(0,0.03)) = 0.007
                _OutLineSpreadY ("Outline Spread", Range(0,0.03)) = 0.007
                _Color("Outline Color", Color) = (1.0,1.0,1.0,1.0)
            }
         
            SubShader
     
        {
            Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
            ZWrite Off Blend SrcAlpha One$$anonymous$$inusSrcAlpha Cull Off
            Lighting Off
            LOD 110
     
            CGPROGRA$$anonymous$$
            #pragma surface surf Lambert alpha
     
            struct Input 
            {
                float2 uv_$$anonymous$$ainTex;
                fixed4 color : COLOR;
            };
     
            sampler2D _$$anonymous$$ainTex;
            float _OutLineSpreadX;
            float _OutLineSpreadY;
            float4 _Color;
     
            void surf(Input IN, inout SurfaceOutput o)
            {
                 fixed4 tex1 = tex2D(_$$anonymous$$ainTex, IN.uv_$$anonymous$$ainTex+float2(_OutLineSpreadX,0.0));
                 fixed4 tex2 = tex2D(_$$anonymous$$ainTex, IN.uv_$$anonymous$$ainTex-float2(_OutLineSpreadX,0.0));
                 fixed4 tex3 = tex2D(_$$anonymous$$ainTex, IN.uv_$$anonymous$$ainTex+float2(0.0,_OutLineSpreadY));
                 fixed4 tex4 = tex2D(_$$anonymous$$ainTex, IN.uv_$$anonymous$$ainTex-float2(0.0,_OutLineSpreadY));
                fixed4 TempColor = tex1 + tex2;
                TempColor = TempColor + tex3 + tex4;
                if(TempColor.a > 0.1){
                    TempColor.a = 1;
                }
                   fixed4 AlphaColor = fixed4(TempColor.a,TempColor.a,TempColor.a,TempColor.a);
                fixed4 mainColor = AlphaColor * _Color.rgba;
                fixed4 addcolor = tex2D(_$$anonymous$$ainTex, IN.uv_$$anonymous$$ainTex) * IN.color;
     
                if(addcolor.a > 0.95){
                    mainColor = addcolor;
                }
     
                o.Albedo = mainColor.rgb;
                o.Alpha = mainColor.a;
            }
            ENDCG       
        }
     
        SubShader 
        {
           Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
            ZWrite Off Blend One One$$anonymous$$inusSrcAlpha Cull Off Fog { $$anonymous$$ode Off }
            LOD 100
            Pass {
                Tags {"Light$$anonymous$$ode" = "Vertex"}
                Color$$anonymous$$aterial AmbientAndDiffuse
                Lighting off
                SetTexture [_$$anonymous$$ainTex] 
                {
                    Combine texture * primary double, texture * primary
                }
            }
        }
        Fallback "Diffuse", 1
 }

avatar image meat5000 ♦ Bladynator · Apr 03, 2017 at 04:29 PM 0
Share

Where does the error appear? I've neither got the thing to work or err.

Show more comments

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by tanoshimi · Apr 04, 2017 at 08:57 AM

Do you need D3D9 support? Have you tried excluding that target?

Comment
Add comment · Show 4 · 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 Bladynator · Apr 04, 2017 at 09:16 AM 0
Share

Yes, this worked! I don't need D3D9 support for now, so at least I can keep on testing. Thank you!

avatar image meat5000 ♦ · Apr 04, 2017 at 09:19 AM 0
Share

@tanoshimi Do you know what it is that might be causing the error?

avatar image tanoshimi meat5000 ♦ · Apr 04, 2017 at 10:35 AM 0
Share

No, I don't know. I was just making a hypothesis based on the error message, which stated it was a problem with D3D9 compilation.

avatar image lilinjie_ · Mar 19, 2018 at 01:23 PM 0
Share

How can I excluding D3D9 support? I don't know shader program.

Follow this Question

Answers Answers and Comments

108 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

Related Questions

jungle terrain problem 0 Answers

worldPos in shader giving errors when game is paused 0 Answers

[Solved] False "variable not assigned" error 3 Answers

Shader Error GLSL error 0 Answers

Need help with shader not working! 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