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 /
  • Help Room /
avatar image
0
Question by TahitiJu · Sep 04, 2018 at 09:38 PM · shadermaterialimagespriterenderer

How to play a material's shader in an image? (Unity 5.2.0f3)

Hi guys, I'm playing a material compose of a shader in a Sprite Renderer that way:

 spriteRenderer = background.GetComponentInChildren<SpriteRenderer>();
 spriteRendererMaterial = Instantiate(background.GetComponentInChildren<SpriteRenderer>().material);
 spriteRendererMaterial.SetFloat("Slider_Dissolve", 1.5f);
 spriteRenderer.material = spriteRendererMaterial;

But then I would like to apply that same material in an image but it doesn't work. I mean that I can see the material being updated in the "Project View". It looked great but nothing happens when I launch the game. There are absolutely no masks in any of my components compared to: https://forum.unity.com/threads/trying-to-animate-an-image-component-material-shader.265023/ I'm running low on solutions any help would be appreciated. Thanks,

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
0

Answer by TahitiJu · Sep 29, 2018 at 02:07 PM

EDIT:

After posting my problem in another forum: https://gamedev.stackexchange.com/questions/163653/how-to-play-a-materials-shader-in-an-image-unity-5-2-0f3

We tried something else:

 IEnumerator WaitForInteractiveElementTransform(Animator animator)
 {
     if (animator != null)
     {
         while (animator.GetCurrentAnimatorStateInfo(0).length >
            animator.GetCurrentAnimatorStateInfo(0).normalizedTime)
         {
             yield return null;
         }
     }
     if (animatorBackground != null)
     {
         animatorBackground.SetBool("On", true);
     }
     else
     {
         P4.gameObject.SetActive(false);
         P4Fantasy.gameObject.SetActive(true);
     }
     state = SceneState.Unreal;
     StartCoroutine(SetMaterialFloatOverTime(spriteRendererMaterial, 1.5f, "Slider_Dissolve"));
 
 private IEnumerator SetMaterialFloatOverTime(Material material, float duration, string propertyName)
 {
     float timer = 0;
     while (timer < duration)
     {
         material.SetFloat(propertyName, timer);
         spriteRenderer.material = material;
         timer += Time.deltaTime;
         yield return null;
     }
  }

But unfortunately the same problem: We see the slider moving in the Unity inspector, but in-game the transition of the material isn't updating.

Here a topic we thought it would help: https://forum.unity.com/threads/material-isnt-updating-when-using-setfloat.530548/ Unfortunately nope. Here our shader:

 Shader "Shader Forge/SpriteDissolve" {
 Properties {
     _Slider_Dissolve ("Slider_Dissolve", Range(0, 1.5)) = 1.5
     _Slider_Border ("Slider_Border", Color) = (1,0.7655173,0,1)
     _Slider_Transition ("Slider_Transition", Range(0, 0.2)) = 0.1083302
     _0RED1GREEN2BLUE ("0 = RED // 1 = GREEN // 2= BLUE", Float ) = 0
     _Texture2 ("Texture 2", 2D) = "white" {}
     _Texture1 ("Texture 1", 2D) = "white" {}
     [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
 }
 SubShader {
     Tags {
         "IgnoreProjector"="True"
         "Queue"="Transparent"
         "RenderType"="Transparent"
         "CanUseSpriteAtlas"="True"
         "PreviewType"="Plane"
     }
 
     Blend SrcAlpha OneMinusSrcAlpha
 
     Pass {
         Name "FORWARD"
         Tags {
             "LightMode"="ForwardBase"
         }
 
         Blend One OneMinusSrcAlpha
         Cull Off
         ZWrite Off
 
         CGPROGRAM
         #pragma vertex vert
         #pragma fragment frag
         #define UNITY_PASS_FORWARDBASE
         #pragma multi_compile _ PIXELSNAP_ON
         #include "UnityCG.cginc"
         #pragma multi_compile_fwdbase
         #pragma exclude_renderers gles3 metal d3d11_9x xbox360 xboxone ps3 ps4 psp2 
         #pragma target 3.0
         uniform float _Slider_Dissolve;
         uniform float4 _Slider_Border;
         uniform float _Slider_Transition;
         uniform float _0RED1GREEN2BLUE;
         uniform sampler2D _Texture2; uniform float4 _Texture2_ST;
         uniform sampler2D _Texture1; uniform float4 _Texture1_ST;
         struct VertexInput {
             float4 vertex : POSITION;
             float2 texcoord0 : TEXCOORD0;
         };
         struct VertexOutput {
             float4 pos : SV_POSITION;
             float2 uv0 : TEXCOORD0;
         };
         VertexOutput vert (VertexInput v) {
             VertexOutput o = (VertexOutput)0;
             o.uv0 = v.texcoord0;
             o.pos = mul(UNITY_MATRIX_MVP, v.vertex );
             #ifdef PIXELSNAP_ON
                 o.pos = UnityPixelSnap(o.pos);
             #endif
             return o;
         }
         float4 frag(VertexOutput i, float facing : VFACE) : COLOR {
             float isFrontFace = ( facing >= 0 ? 1 : 0 );
             float faceSign = ( facing >= 0 ? 1 : -1 );
 ////// Lighting:
 ////// Emissive:
             float4 _Texture1_var = tex2D(_Texture1,TRANSFORM_TEX(i.uv0, _Texture1));
             float4 _Texture2_var = tex2D(_Texture2,TRANSFORM_TEX(i.uv0, _Texture2));
             float node_9964_if_leA = step(1.0,_0RED1GREEN2BLUE);
             float node_9964_if_leB = step(_0RED1GREEN2BLUE,1.0);
             float node_6089 = (lerp((node_9964_if_leA*_Texture1_var.b)+(node_9964_if_leB*_Texture1_var.r),_Texture1_var.g,node_9964_if_leA*node_9964_if_leB)*length((1.0 - i.uv0)));
             float node_2567 = step(node_6089,_Slider_Dissolve);
             float3 emissive = lerp(lerp(_Texture1_var.rgb,_Texture2_var.rgb,node_2567),_Slider_Border.rgb,(node_2567*step(_Slider_Dissolve,(node_6089+_Slider_Transition))*0.1));
             float3 finalColor = emissive;
             return fixed4(finalColor,1);
         }
         ENDCG
     }
 }
 FallBack "Diffuse"
 CustomEditor "ShaderForgeMaterialInspector"
 }

We hope someone can help us solve our problem Thanks!

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

216 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 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

Textures are pure white in project window 1 Answer

Unity C# - How do I make a tilemap on a plane on its shader using a sprite-sheet? 0 Answers

Do you know how to create this wall 2 Answers

Need help with Sprite shadow shader!!! 0 Answers

Tint a UI sprite with a gradient 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