Unity Community


Page 1 of 2 12 LastLast
Results 1 to 20 of 34

  1. Location
    Winchester, VA, USA
    Posts
    21

    Transparent water for indie

    How would I go about making a transparent versoin of the non-reflective/refractive water that comes with Unity indie?
    I've been using unity for a few months now and I'm sill desperately lost when it comes to shaders.
    I'm trying to use the fresnel effect in the water shader to conrol alpha as well as color, and I can't figure out how. Has anyone else tried this?

  2. Unity Graphics Developer

    Location
    Unity Technologies, basement
    Posts
    3,974
    Here's the modified Non-reflective water shader from Unity 1.5, made to be transparent based on fresnel. Just add this to project and select new shader in water material.

    The changes were: added
    Code:  
    1. Tags { "Queue" = "Transparent" }
    2. Blend SrcAlpha OneMinusSrcAlpha
    3. ColorMask RGB
    at start of each SubShader; this puts water into Transparent objects rendering queue, sets up standard blending and sets it to not modify alpha (just in case you'll want glow...).

    Then I set both fragment program and R9000 subshaders to output fresnel into alpha:
    Code:  
    1. col.a = water.a;
    at end of fragment program and
    Code:  
    1. MOV r0.a, r2.a;
    at end of R9000 fragment assembly shader
    Attached Files


  3. Location
    Stockholm, Sweden
    Posts
    773
    What is the correct way to modify the fresnel influence? Let's say I want the surface to maintain some level of opacity regardless of the angle relative to the camera?

    I've modified it by multiplying the water.a (col.a=water.a*2 for example), which works but I am fairly certain it is a dirty and dangerous practice. I will read up on the shaders ASAP, but in the meantime I would be very thankful for some hints.

    TIA!
    Daniel

  4. Unity Graphics Developer

    Location
    Unity Technologies, basement
    Posts
    3,974
    You can just do something like
    Code:  
    1. col.a = 0.5;
    Or better yet, expose it as a color property that can be tweaked. Otherwise, the fresnel is read from the Color/fresnel texture; if you want alpha to be different from fresnel maybe it makes sense to expose a new texture that just controls alpha.

  5. Administrator
    Location
    Copenhagen
    Posts
    1,586
    Your original idea is exactly what I would do. Except - I wouldn't multiply by 2, but instead modify the lookup textures.

    If you think about it: The color gradients used in the value are used for exactly that purpose; to change appearance depending on viewer angle-of-incidence.

    Since you're talking about the indie water, there are no reflections to be affected by the gradient alphs - knock yourself out and make a nice gradient for your transparent.

    And besides; With shaders, if it looks good, ship it!


  6. Location
    Stockholm, Sweden
    Posts
    773
    Many thanks!
    Will look into how to expose properties to enable me to tweak a gradient for the alpha. Will definitely post the shader and source stuff if I make something spectacular.

    Thanks again!


  7. Location
    Massachusetts
    Posts
    1,796
    I know this is sorta gravedigging, but how would you go about changing the amount of alpha on this shader? Sorry, I'm terrible with that ShaderLab language. >.< Thanks!


  8. Location
    Winchester, VA, USA
    Posts
    21
    You don't need to touch the shader. The alpha is controlled by the "oceangradient" image's alpha channel, which you can easily alter in Photoshop.

    One idea I've been toying with is inverting the alpha and using a upside-down duplicate of the scene for limited reflection effects.


  9. Posts
    1,640
    >>I know this is sorta gravedigging

    not at all! this is a great water shader for indie. i didn't look should be in the standard assets if it isn't. *cough* but then again... i didn't look!


  10. Location
    Massachusetts
    Posts
    1,796
    Hey Reznic. What exactly am I supposed to do with the Alpha channel? I tried messing around with the Channel settings, changing numbers and such, but it didn't really have any effect.


  11. Location
    Tucson, AZ
    Posts
    845
    I suppose I could use a little help here, too. I'd like to alter it so the angle of incidence is not so extreme, but I don't quite understand how the gradient affects it.


  12. Location
    Winchester, VA, USA
    Posts
    21
    To access the incidence gradient you look in Standard Assets/Water/Sources/oceangradient. If you bring that into Photoshop (I'm not sure about substitutes) you can alter the color of the gradient and/or alter the alpha of the gradient by going to the "Channels" tab of the layer window. You can run Brightness/Contrast, Curves, or anything else on the alpha to change the steepness of the incidence angle. you can even create a completely different gradient for different effects. Of course, if part of the image is white it be completely opaque, or completely transparent if it's black. You can make it so that the water is always slightly opaque by making sure the lowest value is something lighter than black.
    I'm not sure precisely how the opacity/intesity of the "Horizon Color" property is conrolled, but it too seems to be tied to the incidence gradient.



  13. Location
    Massachusetts
    Posts
    1,796
    Thanks Rez. I think I found the perfect consistancy for my water. It looks great!


  14. Location
    Tucson, AZ
    Posts
    845
    Editing the gradient and the horizon color allow some interesting effects, for sure. Is there a way I can get it so, when viewed from directly above, the ripples aren't invisible right in front of the camera? I can tell it must have something to do with what's being done to viewDir, but the code is opaque to me.


  15. Location
    Massachusetts
    Posts
    1,796
    I had to transfer my files between computers and on my current computer the Shader is broken. It isn't translucent and there are no waves on the surface.


  16. Posts
    1,640
    check your vid drivers or if your card isn't good enough. doubt the shader's broken. more likely something with your card.

  17. Unity Graphics Developer

    Location
    Unity Technologies, basement
    Posts
    3,974
    Moldorma: what is your video card?


  18. Location
    Massachusetts
    Posts
    1,796
    GeForce 2 MX. I didn't even think about that. This computer is two or three years older than the other one, and I never upgraded the video card.


  19. Location
    Tucson, AZ
    Posts
    845
    Is there a special way to prepare the transparent water material to use it with a different mesh? I'm getting this "smearing" effect when I apply it to an imported mesh, as if its uvs were weird.
    Attached Images  

  20. Unity Graphics Developer

    Location
    Unity Technologies, basement
    Posts
    3,974
    How do you apply it? The easiest way to change the water mesh is described here - just changing the mesh used.

    If you're setting up water from scratch, you also have to add all required cameras, scripts etc.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •