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
0
Question by moosefetcher · Jan 25, 2016 at 07:30 PM · renderingalphasurface shader

Cant seem to render alpha surface shader BEHIND geometry

Hello there. I'm attempting to add a spherical 'glow' behind my planets in a space exploration game. There are 2 issues:

1) I can't seem to get the effect to render before (behind) the geometry in my scene. I've tried setting the Tag as "Queue"="Background", "Queue"="Geometry - 1" in combination with both "RenderType"="Opaque" and "RenderType"="Transparent", all without luck. The planet surface is rendering in the Geometry queue and I've also tried adding a 'forward' offset to that. Both the planet surface and the atmosphere glow seem to be jostling for render position, creating a frantic, moving mosaic. That looks real bad.

2) When I include this line...

 #pragma surface surf Lambert alpha:fade

..I get the alpha effect, but then the entire object disappears at distance. This being a space game, the distances are large, but I'm talking about a few thousand units. When I don't include the 'alpha:fade' part, the alpha does not render (everything is opaque).

Here's the surface shader, which gets passed an atmosphere tint Color and an atmosphere density float.

 Shader "Custom/planet glow" {
     Properties {
         _glowTint ("Glow Tint", Color) = (0.5,0.8,1,1)
         _atmosphereMix ("Atmosphere Mix", float) = 0
     }
     SubShader {
         Tags { "RenderType"="Opaque" "Queue"="Background" }
         Cull Front // I want only the far faces to render (behind the actual planet surface)
         
         CGPROGRAM
         #pragma surface surf Lambert alpha:fade
         #pragma target 4.0
    
         struct Input {
             float3 viewDir;
         };
 
         fixed4 _glowTint;
         float _atmosphereMix;        
 
         void surf (Input IN, inout SurfaceOutput o) {
             o.Albedo = _glowTint * _atmosphereMix;
             float cameraNormalDP = saturate(dot( normalize(IN.viewDir), -o.Normal ) * 4.5);
             o.Alpha = cameraNormalDP * cameraNormalDP * cameraNormalDP; // makes the edge fade 'faster'
             o.Emission = _glowTint * _atmosphereMix;
         }
 
         ENDCG
     } 
     FallBack "Diffuse"
 }

If anyone has any pointers as to what I'm missing, that would be great! Cheers.

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 moosefetcher · Jan 26, 2016 at 01:30 PM 0
Share

I should add that I have since been trying various combinations of settings for ZTest and ZWrite in both this shader and the shader for the planet surface. Oddly, when I set the planet to ZTest Always (which, apparently, is supposed to render the pixel, irrespective of depth), I'm still getting the crazy interference mosaic. If anyone could help, that would be a brain saver!

avatar image moosefetcher · Jan 26, 2016 at 03:53 PM 0
Share

I have now also tried 'Offset value, value' in the glow shader, to put it 'behind' the planet surface. This partially works (SO$$anonymous$$E z-fighting artifacts are still visible though) AND I have tried instantiating the glow at 3x the size and positioning it 3x as far away as the planet sphere. This, bizarrely has also not worked! I have tried this method, with both shaders' RenderTypes and Queues different AND the same. Anyone know what might be going on?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by FortisVenaliter · Jan 27, 2016 at 07:49 PM

Are you using a sphere or a plane to draw the glow? If it's a sphere, try turning it inside out. That way the front will be culled, but the back will be rendered, behind the planet. If it's a plane, put it physically behind the planet.

Comment
Add comment · Show 2 · 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 moosefetcher · Feb 07, 2016 at 06:54 PM 0
Share

I'm using a sphere; the shader above culls front faces and inverts the normals (at line 23) - so, basically, exactly what you're suggesting. I'm still getting z-fighting (or, at best, some of the planet surface polygons are flickering). I have even tried positioning the 'glow' sphere further away from the camera than the planet surface sphere (and expanding its radius by the same proportion) and STILL I'm getting z-fighting. But thanks for the reply. If you have any other ideas, it would be great to hear them!

avatar image FortisVenaliter moosefetcher · Feb 09, 2016 at 08:54 PM 0
Share

Then your camera near and far planes are simply too far apart. You need to increase the near-clip or utilize multiple cameras.

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

36 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

Related Questions

Distant object won't render in 'distance camera' 0 Answers

How do I add alpha writes to this shader? 0 Answers

RenderTexture Painting - color blending issues 1 Answer

What happens when the alpha value is outside the 0..1 range in surface shader lighting models? 0 Answers

Luminance to 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