-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Painter's algorithm, fix Sliced
- Loading branch information
Showing
10 changed files
with
242 additions
and
143 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
layout(set = 1, binding = 1) uniform c_Locals { | ||
uvec4 u_ScreenSize; // XY = size | ||
uvec4 u_Params; | ||
vec4 u_CamOriginDir; // XY = origin, ZW = dir | ||
vec4 u_SampleRange; // XY = X range, ZW = y range | ||
}; | ||
|
||
vec2 generate_scatter_pos(vec2 source_coord) { | ||
float y; | ||
if (true) { | ||
float y_sqrt = mix( | ||
sqrt(abs(u_SampleRange.z)) * sign(u_SampleRange.z), | ||
sqrt(abs(u_SampleRange.w)) * sign(u_SampleRange.w), | ||
source_coord.y | ||
); | ||
y = y_sqrt * y_sqrt * sign(y_sqrt); | ||
} else { | ||
y = mix(u_SampleRange.z, u_SampleRange.w, source_coord.y); | ||
} | ||
|
||
float x_limit = mix( | ||
u_SampleRange.x, u_SampleRange.y, | ||
(y - u_SampleRange.z) / (u_SampleRange.w - u_SampleRange.z) | ||
); | ||
float x = mix(-x_limit, x_limit, source_coord.x); | ||
|
||
return u_CamOriginDir.xy + u_CamOriginDir.zw * y + | ||
vec2(u_CamOriginDir.w, -u_CamOriginDir.z) * x; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//!include vs:globals.inc vs:terrain/locals.inc vs:surface.inc fs:surface.inc fs:color.inc | ||
|
||
layout(location = 0) varying vec3 v_TexCoord; | ||
layout(location = 1) flat varying uint v_Type; | ||
|
||
#ifdef SHADER_VS | ||
|
||
void main() { | ||
float total_pixels = float(u_ScreenSize.x * u_ScreenSize.y); | ||
uint pixel_index = uint(total_pixels * float(gl_InstanceIndex) / float(u_Params.x)); | ||
|
||
uvec2 pixel_pos = uvec2(pixel_index % u_ScreenSize.x, pixel_index / u_ScreenSize.x); | ||
vec2 source_coord = 2.0 * vec2(pixel_pos) / vec2(u_ScreenSize.xy) - 1.0; | ||
vec2 pos = generate_scatter_pos(source_coord); | ||
|
||
Surface suf = get_surface(pos); | ||
float altitude = gl_VertexIndex == 3 ? suf.high_alt : | ||
gl_VertexIndex == 2 ? suf.low_alt + suf.delta : | ||
gl_VertexIndex == 1 ? suf.low_alt : 0.0; | ||
|
||
v_Type = gl_VertexIndex < 2 ? suf.low_type : suf.high_type; | ||
v_TexCoord = vec3(suf.tex_coord, altitude / u_TextureScale.z); | ||
gl_Position = u_ViewProj * vec4(pos, altitude, 1.0); | ||
} | ||
#endif //VS | ||
|
||
|
||
#ifdef SHADER_FS | ||
//imported: Surface, u_TextureScale, get_surface, evaluate_color | ||
|
||
layout(location = 0) out vec4 o_Color; | ||
|
||
void main() { | ||
//TODO: move most of the evaluation to the vertex shader | ||
o_Color = evaluate_color(v_Type, v_TexCoord.xy, v_TexCoord.z, 1.0); | ||
} | ||
#endif //FS |
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
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
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
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
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
Oops, something went wrong.