Skip to content

Instantly share code, notes, and snippets.

@NovemberDev
Last active December 16, 2019 11:30
Show Gist options
  • Save NovemberDev/d4a09cc1708a1b0ce42bccec64ccb968 to your computer and use it in GitHub Desktop.
Save NovemberDev/d4a09cc1708a1b0ce42bccec64ccb968 to your computer and use it in GitHub Desktop.
A shader that adds curvature to meshes in godot
/*
Adds curvature to any mesh.
Author: @November_Dev
*/
shader_type spatial;
render_mode world_vertex_coords, depth_draw_alpha_prepass, cull_disabled, vertex_lighting;
uniform float CURVATURE;
uniform float CURVATURE_ACTIVE;
uniform float CURVATURE_DISTANCE;
uniform sampler2D BASE_TEX;
void vertex() {
if(CURVATURE_ACTIVE == 1.0) {
NORMAL = (WORLD_MATRIX * vec4(NORMAL, 0.0)).xyz;
float dist = length(CAMERA_MATRIX[3].xyz - VERTEX) / CURVATURE_DISTANCE;
VERTEX.y -= pow(dist, CURVATURE);
}
}
void fragment() {
vec4 tex = texture(BASE_TEX, UV);
if(tex.a < 0.3) {
discard;
}
ALBEDO = tex.rgb;
ALPHA = tex.a;
}
@hman278
Copy link

hman278 commented Dec 5, 2019

My most beloved github account.

@Calinou
Copy link

Calinou commented Dec 16, 2019

@NovemberDev Could you upload it to the asset library as a reusable shader? It'd help people discover it 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment