Last active
December 16, 2019 11:30
-
-
Save NovemberDev/d4a09cc1708a1b0ce42bccec64ccb968 to your computer and use it in GitHub Desktop.
A shader that adds curvature to meshes in godot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@NovemberDev Could you upload it to the asset library as a reusable shader? It'd help people discover it 🙂