- Home /
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
}
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.
Bump, still need help with vertex atmosphere shader issue.
Your answer
Follow this Question
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