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
1
Question by MoistJohn · Mar 04, 2013 at 09:32 AM · shadersfragmentvertexshader

using two shaders together

Hi. I created my own vertex shader that manipulates the vertex position with a function of two variables. I attached it to a material and placed it as the second material on the object that already has the default-diffuse material. The result is this criss-cross of color that shifts as the camera move.

What should I do? can i "direct" the fragment part of my shader to be the diffuse one? is there a way i can "turn off" my fragment shader so there won't be two active ones?

Here is the shader:

Shader "Custom/ShockwaveShader" { Properties { _TimeFromExp("TimeSinceExplosion", float) = 1 _ExplosionPos("ExplosionPosition", Vector) = (0,0,0) }

 SubShader {
     Pass {
 
     CGPROGRAM
     #pragma vertex vert
     #pragma fragment frag
     #include "UnityCG.cginc"
     
     float _TimeFromExp;
     float4 _ExplosionPos;
     
     struct v2f {
         float4 pos: SV_POSITION;
         float3 color: COLOR0;
     };
     
     float dist(float3 a, float3 b) {
         return sqrt( (a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y) + (a.z - b.z)*(a.z - b.z) );
     }
     
     v2f vert (appdata_full v)
     {
         v2f o;
         float dis = dist(v.vertex, _ExplosionPos);
         float4 norm = normalize(v.vertex - _ExplosionPos);
         float funcVal = exp(-pow((dis/5 - _TimeFromExp),2));
         float4 ver = v.vertex + norm*funcVal;
         
         o.pos = mul(UNITY_MATRIX_MVP, ver);
         
         o.color = v.color;
         return o;
     }
     
     half4 frag (v2f i) : COLOR
     {
         return half4(i.color, 1);
     }
 
     ENDCG
     
     }
 }
 Fallback "VertexLit"

}

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 electricsauce · Mar 04, 2013 at 02:50 PM

I think you should only be using one material at a time for the same uv mapped space. If you need a diffuse texture just add it to your shockwave shader and diable/remove the default diffuse shader.

Comment
Add comment · Show 3 · 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 MoistJohn · Mar 04, 2013 at 05:50 PM 0
Share

Cool. How can I use a diffuse fragment shader without implementing one in my shader? I know there is the FallBack option, but that is for compatibility issues. Is there a "for this, go use that ins$$anonymous$$d" option?

Thanks.

avatar image electricsauce · Mar 04, 2013 at 08:30 PM 0
Share

I'm pretty sure I butchered your code, but try this:

 Shader "Custom/ShockwaveShader" { 
 
 Properties {
   _$$anonymous$$ainTex ("Base (RGB)", 2D) = "white" {}
   _TimeFromExp("TimeSinceExplosion", float) = 1
   _ExplosionPos("ExplosionPosition", Vector) = (0,0,0) }
 
     SubShader {
     Tags { "RenderType"="Opaque" }
         LOD 200
         
     Pass {
     
       Cull Back
             Lighting On
     CGPROGRA$$anonymous$$
 // Upgrade NOTE: excluded shader from DX11 and Xbox360; has structs without semantics (struct v2f members uv)
 #pragma exclude_renderers d3d11 xbox360
     #pragma vertex vert
     #pragma fragment frag
     #include "UnityCG.cginc"
      
     float _TimeFromExp;
     float4 _ExplosionPos;
     sampler2D _$$anonymous$$ainTex;
      float4 _$$anonymous$$ainTex_ST;
      
     struct v2f {
     float4 pos: SV_POSITION;
      float2 uv;
     float3 color: COLOR0;
     };
      
     float dist(float3 a, float3 b) {
     return sqrt( (a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y) + (a.z - b.z)*(a.z - b.z) );
     }
      
     v2f vert (appdata_full v)
     {
     v2f o;
     
                 
     float dis = dist(v.vertex, _ExplosionPos);
     float4 norm = normalize(v.vertex - _ExplosionPos);
     float funcVal = exp(-pow((dis/5 - _TimeFromExp),2));
     float4 ver = v.vertex + norm*funcVal;
      
       o.uv = TRANSFOR$$anonymous$$_TEX (v.texcoord, _$$anonymous$$ainTex);  
 
      o.pos = mul(UNITY_$$anonymous$$ATRIX_$$anonymous$$VP, ver);
  
     o.color = v.color;
     return o;
     }
      
 
 float4 frag(v2f i) : COLOR
 {
 float4 c = tex2D (_$$anonymous$$ainTex, i.uv);
     c.rgb = c.rgb  * i.color * 2;
     return c;
     }
      
     ENDCG
      
     }
     }
     Fallback "VertexLit"
 }
 
avatar image electricsauce · Mar 04, 2013 at 08:31 PM 0
Share

also, I got a lot of info from here:

link text

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

11 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

Related Questions

Per-Pixel Shader for Android? 1 Answer

How can I achieve this kind of shading? 1 Answer

How to write to Camera's Depth Buffer with a basic vertex and fragment shader? 0 Answers

2D Water top surface profile 1 Answer

Access to svPosition in fragment shader 1 Answer


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