mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-22 17:18:39 +00:00
Add texture bumpmapping feature.
This commit is contained in:
parent
b850f0f038
commit
3f6f327cb9
11 changed files with 602 additions and 2 deletions
47
client/shaders/bumpmaps_liquids/opengl_fragment.glsl
Normal file
47
client/shaders/bumpmaps_liquids/opengl_fragment.glsl
Normal file
|
@ -0,0 +1,47 @@
|
|||
|
||||
uniform sampler2D myTexture;
|
||||
uniform sampler2D normalTexture;
|
||||
|
||||
uniform vec4 skyBgColor;
|
||||
uniform float fogDistance;
|
||||
|
||||
varying vec3 vPosition;
|
||||
|
||||
varying vec3 viewVec;
|
||||
|
||||
void main (void)
|
||||
{
|
||||
vec4 col = texture2D(myTexture, vec2(gl_TexCoord[0]));
|
||||
float alpha = col.a;
|
||||
vec2 uv = gl_TexCoord[0].st;
|
||||
vec4 base = texture2D(myTexture, uv);
|
||||
vec4 final_color = vec4(0.2, 0.2, 0.2, 1.0) * base;
|
||||
vec3 vVec = normalize(viewVec);
|
||||
vec3 bump = normalize(texture2D(normalTexture, uv).xyz * 2.0 - 1.0);
|
||||
vec3 R = reflect(-vVec, bump);
|
||||
vec3 lVec = normalize(vec3(0.0, -0.4, 0.5));
|
||||
float diffuse = max(dot(lVec, bump), 0.0);
|
||||
|
||||
vec3 color = diffuse * texture2D(myTexture, gl_TexCoord[0].st).rgb;
|
||||
|
||||
|
||||
float specular = pow(clamp(dot(R, lVec), 0.0, 1.0),1.0);
|
||||
vec4 vSpecular = 0.2*specular * diffuse;
|
||||
color += vSpecular;
|
||||
|
||||
|
||||
col = vec4(color.r, color.g, color.b, alpha);
|
||||
col *= gl_Color;
|
||||
col = col * col; // SRGB -> Linear
|
||||
col *= 1.8;
|
||||
col.r = 1.0 - exp(1.0 - col.r) / exp(1.0);
|
||||
col.g = 1.0 - exp(1.0 - col.g) / exp(1.0);
|
||||
col.b = 1.0 - exp(1.0 - col.b) / exp(1.0);
|
||||
col = sqrt(col); // Linear -> SRGB
|
||||
if(fogDistance != 0.0){
|
||||
float d = max(0.0, min(vPosition.z / fogDistance * 1.5 - 0.6, 1.0));
|
||||
alpha = mix(alpha, 0.0, d);
|
||||
}
|
||||
|
||||
gl_FragColor = vec4(col.r, col.g, col.b, alpha);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue