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
1
Question by DoktorAce · Jun 14, 2011 at 05:26 PM · shaderiosiphoneblendingvertexcolor

Problem with texture blending and vertex color shader for iOS

I'm trying to create a shader that uses the vertex colors of the model for lightning, and blends two texture together ( I'm looking for an additive result )

What I got so far is:

 Shader "WarpDash/UnlitVertexColorsAdditiveBlend" {
 Properties {
     _Blend ("Blend", Range (0, 1) ) = 0.5 
     _MainTex ("Texture", 2D) = "white" {}
     _BlendTexture ("Blend Texture", 2D) = "black"
 }
 
 Category {
     Tags { "Queue"="Geometry" }
     Lighting Off
     BindChannels {
         Bind "Color", color
         Bind "Vertex", vertex
         Bind "TexCoord", texcoord
     }
     
     SubShader {
         Pass {
             SetTexture[_MainTex] {
                 Combine texture * primary DOUBLE
             }
               SetTexture [_BlendTexture] {
                    ConstantColor ([_Blend],[_Blend],[_Blend],[_Blend])
                 Combine texture * constant + previous
                }
         }
     }
 }
 }

The shader works as I want when I'm not emulating OpenGL ES2.0. As far as I can figure out "Combine texture * constant + previous" is the problem, but I can't seem to find a way around it. I was hoping I could do this in one pass...

Thanks a bunch!

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 Jessy · Jun 14, 2011 at 07:01 PM

The only three argument combiner function that works on iOS is Combine src1 Lerp(src2) src3, so your second texture stage won't work.

If you need help writing the shader; please tell me exactly what you want to do; I can't tell from your code. (I understand what your code does, but not why. One texture can be overbrightened by vert colors, but the other can't? Is Blend Texture a firey effect?) It's possible it can't be done in one pass with the MBXLite or even GLES 1.1 altogether; if so, do you want a single pass that looks wrong, or two passes that look right?

 Properties {
     _Blend ("Blend", Range (0, 1)) = 0.5
     _MainTex ("Texture (A = Aditive Blend)", 2D) = ""
 }
 
 SubShader {Pass {
     GLSLPROGRAM
     varying lowp vec2 uv;
     varying lowp vec3 color;
     
     #ifdef VERTEX
     void main() {
         gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
         uv = gl_MultiTexCoord0.xy;
         color = gl_Color.rgb * 2.;
     }
     #endif
     
     #ifdef FRAGMENT
     uniform sampler2D _MainTex;
     uniform lowp float _Blend;
     void main() {
         lowp vec4 texture = texture2D(_MainTex, uv);
         gl_FragColor = vec4(texture.rgb * color + texture.a * _Blend, 1);
     }
     #endif        
     ENDGLSL
 }}
 
 SubShader {
     BindChannels {
         Bind "vertex", vertex
         Bind "color", color
         Bind "texCoord", texCoord
     }
     Pass {
         SetTexture[_MainTex] {
             ConstantColor (0,0,0, [_Blend])
             Combine texture * primary Double, texture * constant
         }
         SetTexture[_] {Combine previous + previous alpha}
     }
 }

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 DoktorAce · Jun 15, 2011 at 06:33 AM 0
Share

Hi Jessy,

What I want is a shader that takes the first texture "_$$anonymous$$ainTex" and applies it on the model taking vertex colors into account. I Already have a working version of that kind of shader.

But now I would like to use a seconds texture to add light to the result using a blending slider Think of a texture that has some light sources (leds) textured on it. I want to use a black and white texture to add glow around the lights in the texture ( I need the result to be Additive ).

The above shader does exactly what I want, but since the three argument combiner function I use does not work on the target platform I'm stuck.

I realize that it might not be possible to do in just one pass, but I would like to have this shader anyways. And if its possible to get a similar result using one pass that would be great too!

Thanks alot!

avatar image Jessy · Jun 15, 2011 at 04:29 PM 0
Share

If you "want to use a black and white texture", how about storing it in the alpha channel (code added above)?

avatar image DoktorAce · Jun 15, 2011 at 04:56 PM 0
Share

Hey it works! You just made my day Jessy! Thanks a lot!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

What shader blending modes don't work on iOS? 1 Answer

iOS Shader - Emulator vs Device Inconsistency 0 Answers

how to build impressive shaders for iOS? 1 Answer

Blending 2 textures using vertex COLOR 0 Answers

Vertex color blending 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