mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-20 19:45:22 +02:00
Port shadow shaders to work with OpenGL3
Co-authored-by: sfan5 <sfan5@live.de>
This commit is contained in:
19
client/shaders/shadow/pass1/opengl_fragment.glsl
Normal file
19
client/shaders/shadow/pass1/opengl_fragment.glsl
Normal file
@@ -0,0 +1,19 @@
|
||||
uniform sampler2D ColorMapSampler;
|
||||
varying vec4 tPos;
|
||||
|
||||
#ifdef GL_ES
|
||||
varying mediump vec2 varTexCoord;
|
||||
#else
|
||||
centroid varying vec2 varTexCoord;
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 col = texture2D(ColorMapSampler, varTexCoord);
|
||||
|
||||
if (col.a < 0.70)
|
||||
discard;
|
||||
|
||||
float depth = 0.5 + tPos.z * 0.5;
|
||||
gl_FragColor = vec4(depth, 0.0, 0.0, 1.0);
|
||||
}
|
49
client/shaders/shadow/pass1/opengl_vertex.glsl
Normal file
49
client/shaders/shadow/pass1/opengl_vertex.glsl
Normal file
@@ -0,0 +1,49 @@
|
||||
uniform mat4 LightMVP; // world matrix
|
||||
uniform vec4 CameraPos; // camera position
|
||||
varying vec4 tPos;
|
||||
|
||||
uniform float xyPerspectiveBias0;
|
||||
uniform float xyPerspectiveBias1;
|
||||
uniform float zPerspectiveBias;
|
||||
|
||||
#ifdef GL_ES
|
||||
varying mediump vec2 varTexCoord;
|
||||
#else
|
||||
centroid varying vec2 varTexCoord;
|
||||
#endif
|
||||
|
||||
vec4 getRelativePosition(in vec4 position)
|
||||
{
|
||||
vec2 l = position.xy - CameraPos.xy;
|
||||
vec2 s = l / abs(l);
|
||||
s = (1.0 - s * CameraPos.xy);
|
||||
l /= s;
|
||||
return vec4(l, s);
|
||||
}
|
||||
|
||||
float getPerspectiveFactor(in vec4 relativePosition)
|
||||
{
|
||||
float pDistance = length(relativePosition.xy);
|
||||
float pFactor = pDistance * xyPerspectiveBias0 + xyPerspectiveBias1;
|
||||
return pFactor;
|
||||
}
|
||||
|
||||
vec4 applyPerspectiveDistortion(in vec4 position)
|
||||
{
|
||||
vec4 l = getRelativePosition(position);
|
||||
float pFactor = getPerspectiveFactor(l);
|
||||
l.xy /= pFactor;
|
||||
position.xy = l.xy * l.zw + CameraPos.xy;
|
||||
position.z *= zPerspectiveBias;
|
||||
return position;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 pos = LightMVP * inVertexPosition;
|
||||
|
||||
tPos = applyPerspectiveDistortion(pos);
|
||||
|
||||
gl_Position = vec4(tPos.xyz, 1.0);
|
||||
varTexCoord = (mTexture * vec4(inTexCoord0.xy, 0.0, 1.0)).xy;
|
||||
}
|
Reference in New Issue
Block a user