【Defold】modelコンポーネント用「Shadow」シェーダー
2D影。
目次
シェーダーコード
attribute highp vec4 position;
attribute mediump vec2 texcoord0;
attribute mediump vec3 normal;
uniform mediump mat4 mtx_worldview;
uniform mediump mat4 mtx_view;
uniform mediump mat4 mtx_proj;
uniform mediump mat4 mtx_normal;
uniform mediump vec4 light;
varying highp vec4 var_position;
varying mediump vec3 var_normal;
varying mediump vec2 var_texcoord0;
void main()
{
vec4 p = mtx_worldview * vec4(position.xyz, 1.0);
var_position = p;
var_texcoord0 = texcoord0;
var_normal = normalize((mtx_normal * vec4(normal, 0.0)).xyz);
gl_Position = mtx_proj * p;
}
varying highp vec4 var_position;
varying mediump vec3 var_normal;
varying mediump vec2 var_texcoord0;
uniform lowp sampler2D tex0;
uniform lowp vec4 tint;
uniform lowp vec4 _ShadowX;
uniform lowp vec4 _ShadowY;
uniform lowp vec4 _ShadowAlpha;
uniform lowp vec4 _ShadowColor;
void main()
{
vec4 tint_pm = vec4(tint.xyz * tint.w, tint.w);
vec4 col = texture2D(tex0, var_texcoord0.xy) * tint_pm;
float shadowA = texture2D(tex0, var_texcoord0.xy + vec2(_ShadowX.w, _ShadowY.w)).w;
col.xyz += (_ShadowColor.xyz * shadowA) * (1.0 - col.w);
col.w = max(shadowA * _ShadowAlpha.w * tint.w, col.w);
gl_FragColor = col;
}
マテリアルの設定はこちらです。