- Home /
Question by
hirohayashivfx · Aug 25, 2020 at 02:28 PM ·
shaderglsl
I cant get the GLSL Shader working,,,
I wanted to do make a shield effect.Like the URL below.
https://qiita.com/edo_m18/items/63df01d0efe394c515b0
I changed the [varying] to [out] but it will not work as expected. I tried but cant find the answer.Can somebody helpme,,,?
Thanks.
Shader "Unlit/Shield"
{
Properties
{
_MainTex("Texture", 2D) = "white" {}
_Color("Color", Color) = (1, 1, 1, 0.5)
}
SubShader
{
Tags { "Queue" = "Transparent" }
Pass
{
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
GLSLPROGRAM
uniform vec4 _Color;
uniform vec3 _WorldSpaceCameraPos;
uniform mat4 _Object2World;
uniform mat4 _World2Object;
out vec3 varyingNormalDirection;
out vec3 varyingViewDirection;
#ifdef VERTEX
void main()
{
mat4 modelMatrix = _Object2World;
mat4 modelMatrixInverse = _World2Object;
varyingNormalDirection = normalize(vec3(vec4(gl_Normal, 0.0) * modelMatrixInverse));
varyingViewDirection = normalize(_WorldSpaceCameraPos - vec3(modelMatrix * gl_Vertex));
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
#endif
#ifdef FRAGMENT
void main()
{
vec3 normalDirection = normalize(varyingNormalDirection);
vec3 viewDirection = normalize(varyingViewDirection);
float newOpacity = min(1.0, _Color.a / abs(dot(viewDirection, normalDirection)));
gl_FragColor = vec4(_Color.rgb, newOpacity);
}
#endif
ENDGLSL
}
}
}
Comment
Your answer
Follow this Question
Related Questions
ES2.0 Diffuse Shader? 0 Answers
GLSL shader - array of uniform const 0 Answers
Sizeof float in cg shader 1 Answer
How can I make my own shader include file (.cginc or .glslinc)? 2 Answers
clipping shader for OpenGL quad 0 Answers