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 Ross_S · Oct 07, 2013 at 09:35 AM · shaderrendertexturealphablend

Alpha values not blending in RenderTexture

alt textThe problem I'm having is that when I draw a new texture into the RenderTexture, instead of blending with the texture that's already there (the render texture is set to clear "depth only" - though same thing happens with "don't clear") ... the alpha value of the new texture REPLACES instead of blending with the texture that's already there...

the texture that's already there has not been drawn this frame - it's only still there because the RenderTexture is set to don't clear, which is as I need it.

The images i've added are -

A) what i see on screen

B) the renderTexture Alpha layer

C) the renderTexrture setup

D) the shader i'm currently using to draw the input texture...

Not sure if it's relevant but i'm also using a depthmask so that only pixels within the shape can be renderer to... (but i've turned it off and same behaviour... so...)

grateful for any leads here :) ta... ![alt text][2]

screen shot 2013-10-07 at 10.28.32 copy copy copy.png (203.7 kB)
Comment
Add comment · Show 2
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 soulburner · Mar 16, 2014 at 03:30 PM 0
Share

I've got the same problem. I'm trying to draw two flat sprites with alpha channels and that render O$$anonymous$$ on the screen, but when rendered to RenderTextrure, the above sprite's alpha channel values just being overwritten, not blended.

Don't know how to solve that.

avatar image Hoeloe soulburner · Mar 16, 2014 at 03:47 PM 0
Share

Don't post this as an answer. This isn't an answer. At best, post it as a comment (I'm converting it to one).

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Hoeloe · Oct 07, 2013 at 09:40 AM

It's not replacing something that's already there, but it's rendering it back to front, and the ZTest argument is causing it to ignore everything behind the semi-transparent pixels, meaning it's not drawn at all. Try removing the ZTest call in the shader.

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 Ross_S · Oct 07, 2013 at 10:09 AM 0
Share

Thanks - I tried removing the ZTest call but it still does exactly the same...

avatar image Hoeloe · Oct 07, 2013 at 10:16 AM 0
Share

Hmmm... I'm afraid I'm not sure then. I'm not hugely familiar with that form of surface shader, I prefer to use the more explicit ones.

avatar image Ross_S · Oct 07, 2013 at 10:34 AM 0
Share

Got one you think i could try? i'm not attached to that one by any means ;)

avatar image Hoeloe · Oct 07, 2013 at 10:41 AM 0
Share

Well, I'm not entirely sure what it is you're trying to render, and it doesn't help that I have no experience with RenderTextures, as I don't have Unity Pro.

avatar image
0

Answer by Owen-Reynolds · Oct 07, 2013 at 03:00 PM

Say you draw a solid cube to the render texture, alpha=1 everywhere. Then you draw an alpha=0.5ish smoke texture over it. That smoke should blend with the cube, but the final alpha should be 1 (the smoke didn't make the cube become transparent.) If any of the smoke went off the edge of the cube, that would have a 0.5 alpha.

Then, using "don't clear" to keep the previous frame (really, all previous frames,) the render texture blends in. The solid aplha=1 cube overwrites, extra 0.5 smoke blends in.

The problem is, a normal "alpha blend with background" (I think) will set the background/destination alpha the same as it sets colors -- to the weighted average. Your solid cube is being turned into a 0.75 alpha by the smoke. No one usually cares, since you never look at background alpha anyway -- you always use src, oneMinusSrc. Or, for render-textures, you just slam it on the screen as the final step. As Hoeloe notes, surface shaders are easier to test (like displaying alpha as grey scale, so you can check it.)

I think, on the initial blend, alpha should be set to Max(src,dest) (if that's even a setting.)

But, always blending with the previous frame seems wrong to me. I'm thinking that whatever effect you're trying to get is going to come some other way. Like a second camera ... .

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 Ross_S · Oct 07, 2013 at 04:28 PM 0
Share

Thanks for your answer - the effect i want is pretty simple really - it'd just be like painting into texture - using a brush the way photoshop does... so if there is already something down that has an alpha of 0.8 and i paint over that pixel with an alpha of 0.1 it's going to be 0.8 or more ... not getting replaced by the 0.1 value...

avatar image Owen-Reynolds · Oct 07, 2013 at 09:14 PM 0
Share

I'd think a "real" painting program would involve having your own Texture2D, which you directly manipulate using setPixel commands. A small hassle (need a nested loops with the correct offsets to apply a brush,) but you have full control over how everything is applied.

Seems "don't clear" might be a fast&dirty way at first, but you're going to eventually have grid marks and other GUI elements, with no good way to separate them from the real image.

avatar image Ross_S · Oct 08, 2013 at 08:36 AM 0
Share

Hi Owen... well the camera that is rendering the RenderTeture will only have the painted images on it... so no GUI or anything there... and then that rendertexture is just one layer of the overall scene... i think setPixel is too slow for this... that's my understanding anyway - thanks for your replies though

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

18 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

Related Questions

Trying to write a simple mixing 2 textures shader with alpha support on the 2d texture 1 Answer

Shader problem with 2D fake lighting 1 Answer

Transparent shader: final alpha value wrong 2 Answers

Shader to render RenderTexture plus alpha? 1 Answer

Blend two texture diffuse shader with alpha 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