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
0
Question by thundax · Mar 17, 2012 at 01:43 PM · spaceplanetvertex shaderfragmentatmosphere

Fragment/Vertex shader complex issue

The shader below is Slin's planet shader, which I've reversed normals on because he had them facing away from lights instead of towards.

The shader works great on static objects and in the scene viewer, but when I apply the shader to a rotating planet, the effect rotates with the mesh instead of staying based on light direction/position and camera position/dircetion.

I want the effect to stay in place when the planet is rotating but the camera isn't.

Also, was wondering how to combine this with a BlinnPhong based specular, normal, and parallax shader to make a single shader. Applying 2 materials causes artifacts.

If they can't be combined into a single shader file, how can I make this shader texture-less?

     Pass
     {
         Name "AtmosphereBase"
         Tags {"LightMode" = "Always"}
         Cull Front
         Blend SrcAlpha One
        
         CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
            
             #pragma fragmentoption ARB_fog_exp2
             #pragma fragmentoption ARB_precision_hint_fastest
            
             #include "UnityCG.cginc"
            
             uniform float4 _Color;
             uniform float4 _AtmoColor;
             uniform float _Size;
             uniform float _Falloff;
             uniform float _Transparency;
            
             struct v2f
             {
                 float4 pos : SV_POSITION;
                 float3 normal : TEXCOORD0;
                 float3 worldvertpos : TEXCOORD1;
             };

             v2f vert(appdata_base v)
             {
                 v2f o;
                
                 v.vertex.xyz += v.normal*_Size;
                 o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
                 o.normal = v.normal;
                 o.worldvertpos = mul(_Object2World, v.vertex);
                
                 return o;
             }
           
             float4 frag(v2f i) : COLOR
             {
                 i.normal = normalize(i.normal);
                 float3 viewdir = normalize(i.worldvertpos-_WorldSpaceCameraPos);
                
                 float4 color = _AtmoColor;
                 color.a = pow(saturate(dot(viewdir, i.normal)), _Falloff);
                 color.a *= _Transparency*_Color*dot(-normalize(i.worldvertpos-_WorldSpaceLightPos0), i.normal);
                 return color;
             }
         ENDCG
     }
Comment
Add comment · Show 4
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 thundax · Mar 17, 2012 at 08:05 PM 0
Share

Got it to be textureless and it now works with the secondary material.

Still need to make the atmosphere effect stay in place based on light direction/position and camera position/direction as the object rotates though.

avatar image thundax · Mar 18, 2012 at 01:07 AM 0
Share

Bump, still need help with vertex atmosphere shader issue.

avatar image thundax · Mar 28, 2012 at 01:59 AM 0
Share

Bump Please

avatar image ScroodgeM · Jul 19, 2012 at 08:13 AM 0
Share

is this task actual?

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to add atmospheric glow to a planet 2 Answers

From within the frag function of a shader, can you access the uv values of vertices? 0 Answers

Random generated debris in empty space 1 Answer

Slindev Planet Shader 3.x Not Working 0 Answers

How to make first-person work in zero-G with planets? 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