-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a lowpoly shader #422
Comments
Certainly possible. You have to write a shader to do it.
--- a/project/addons/terrain_3d/extras/minimum.gdshader
+++ b/project/addons/terrain_3d/extras/minimum.gdshader
@@ -25,6 +25,7 @@ uniform uint _mouse_layer = 0x80000000u; // Layer 32
varying flat vec2 v_uv_offset;
varying flat vec2 v_uv2_offset;
+varying vec3 v_world_vertex;
////////////////////////
// Vertex
@@ -96,6 +97,7 @@ void vertex() {
// Convert model space to view space w/ skip_vertex_transform render mode
VERTEX = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz;
+ v_world_vertex = VERTEX; // Save vertex in world space
VERTEX = (VIEW_MATRIX * vec4(VERTEX, 1.0)).xyz;
NORMAL = normalize((MODELVIEW_MATRIX * vec4(NORMAL, 0.0)).xyz);
BINORMAL = normalize((MODELVIEW_MATRIX * vec4(BINORMAL, 0.0)).xyz);
@@ -140,12 +142,13 @@ void fragment() {
vec2 uv = UV + v_uv_offset;
vec2 uv2 = UV2 + v_uv2_offset;
- // Calculate Terrain Normals. 4 lookups
- vec3 w_tangent, w_binormal;
- vec3 w_normal = get_normal(uv2, w_tangent, w_binormal);
- NORMAL = mat3(VIEW_MATRIX) * w_normal;
- TANGENT = mat3(VIEW_MATRIX) * w_tangent;
- BINORMAL = mat3(VIEW_MATRIX) * w_binormal;
+ // Calculate Terrain Normals
+ vec3 w_tangent = normalize(dFdx(v_world_vertex));
+ vec3 w_binormal = normalize(dFdy(v_world_vertex));
+ vec3 w_normal = normalize(cross(w_tangent, w_binormal));
+ NORMAL = mat3(VIEW_MATRIX) * w_normal * -1.0;
+ TANGENT = mat3(VIEW_MATRIX) * w_tangent;
+ BINORMAL = mat3(VIEW_MATRIX) * w_binormal;
// Apply PBR
ALBEDO=vec3(.2); In the picture above, I also enabled the heightmap debug view. The shader code is in our repo. Customize the shader to texture the terrain as you like. Hacking on the main shader: Here it is with texture UVs at 0.001, though this is sloppy. You see large squares due to nearest texture filtering, and triangle panels due to flat normals. Between vertices you see the shader blending textures and the texture blocks don't line up with the mesh triangles. This isn't the true low poly look, and is more costly than a low poly shader. It should be like the grey image above. If using the main shader, what should be done is:
|
@TokisanGames Oh, Thanks. |
HTerrain has this feature, wish has some help: https://hterrain-plugin.readthedocs.io/en/latest/#lowpoly |
What is on that documentation page is how to get flat normals. We've already discussed how to show flat normals on our terrain above. All that is remaining is painting with simple textures if you want the look in the picture. Also see #435 This issue and #435 already show how to do low poly shaders. It will remain open until someone makes a premade one for our extras directory. |
Description
maybe there was a way to create lowpoly style terrain in current state. but i don't know to do it.
if it can:
can make a toturial in docs how to do this?
if not:
can implement this feature?
The text was updated successfully, but these errors were encountered: