Skip to content
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

Textured meshscatter #1406

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions GLMakie/assets/shader/mesh.frag
Expand Up @@ -14,6 +14,7 @@ in vec3 o_normal;
in vec3 o_lightdir;
in vec3 o_camdir;
in vec4 o_color;
in vec2 o_uv_scale;
in vec2 o_uv;
flat in uvec2 o_id;

Expand Down Expand Up @@ -82,18 +83,17 @@ vec4 get_color(sampler1D color, vec2 uv, vec2 color_norm, sampler1D color_map, s
}

uniform bool fetch_pixel;
uniform vec2 uv_scale;

vec4 get_pattern_color(sampler1D color) {
int size = textureSize(color, 0);
vec2 pos = gl_FragCoord.xy * uv_scale;
vec2 pos = gl_FragCoord.xy * o_uv_scale;
int idx = int(mod(pos.x, size));
return texelFetch(color, idx, 0);
}

vec4 get_pattern_color(sampler2D color){
ivec2 size = textureSize(color, 0);
vec2 pos = gl_FragCoord.xy * uv_scale;
vec2 pos = gl_FragCoord.xy * o_uv_scale;
return texelFetch(color, ivec2(mod(pos.x, size.x), mod(pos.y, size.y)), 0);
}

Expand Down
5 changes: 4 additions & 1 deletion GLMakie/assets/shader/mesh.vert
Expand Up @@ -21,8 +21,10 @@ void render(vec4 position_world, vec3 normal, mat4 view, mat4 projection, vec3 l
vec4 get_color_from_cmap(float value, sampler1D color_map, vec2 colorrange);

uniform uint objectid;
flat out uvec2 o_id;
uniform vec2 uv_scale;

flat out uvec2 o_id;
out vec2 o_uv_scale;
out vec2 o_uv;
out vec4 o_color;

Expand Down Expand Up @@ -60,6 +62,7 @@ void main()
{
o_id = uvec2(objectid, gl_VertexID+1);
vec2 tex_uv = to_2d(texturecoordinates);
o_uv_scale = uv_scale;
o_uv = vec2(1.0 - tex_uv.y, tex_uv.x) * uv_scale;
o_color = to_color(vertex_color, color_map, color_norm);
vec3 v = to_3d(vertices);
Expand Down
7 changes: 6 additions & 1 deletion GLMakie/assets/shader/particles.vert
Expand Up @@ -36,6 +36,7 @@ uniform int len;
flat out uvec2 o_id;
out vec4 o_color;
out vec2 o_uv;
out vec2 o_uv_scale;

{{position_type}} position;

Expand Down Expand Up @@ -93,6 +94,9 @@ vec4 get_particle_color(sampler2D color, Nothing intensity, Nothing color_map, N

void render(vec4 position_world, vec3 normal, mat4 view, mat4 projection, vec3 lightposition);

{{uv_scale_type}} uv_scale;
vec2 get_uv_scale(vec2 uv_scale, int index) { return uv_scale; }
vec2 get_uv_scale(samplerBuffer uv_scale, int index) { return texelFetch(uv_scale, index).xy; }
vec2 get_uv(Nothing x){return vec2(0.0);}
vec2 get_uv(vec2 x){return vec2(1.0 - x.y, x.x);}

Expand All @@ -106,7 +110,8 @@ void main(){
{{position_calc}}
o_color = get_particle_color(color, intensity, color_map, color_norm, index, len);
o_color = o_color * to_color(vertex_color);
o_uv = get_uv(texturecoordinates);
o_uv_scale = get_uv_scale(uv_scale, index);
o_uv = o_uv_scale * get_uv(texturecoordinates);
rotate(rotation, index, V, N);
render(model * vec4(pos + V, 1), N, view, projection, lightposition);
}
2 changes: 2 additions & 0 deletions GLMakie/assets/shader/surface.vert
Expand Up @@ -51,6 +51,7 @@ uniform uint objectid;
uniform vec2 uv_scale;
flat out uvec2 o_id;
out vec4 o_color;
out vec2 o_uv_scale;
out vec2 o_uv;

void main()
Expand All @@ -63,6 +64,7 @@ void main()
{{position_calc}}

o_id = uvec2(objectid, index1D+1);
o_uv_scale = uv_scale;
o_uv = index01 * uv_scale;
vec3 normalvec = {{normal_calc}};

Expand Down
2 changes: 1 addition & 1 deletion GLMakie/src/glshaders/particles.jl
Expand Up @@ -62,7 +62,7 @@ function draw_mesh_particle(screen, p, data)
matcap = nothing => Texture
fetch_pixel = false
interpolate_in_fragment_shader = false
uv_scale = Vec2f(1)
uv_scale = Vec2f(1) => TextureBuffer

instances = const_lift(length, position)
shading = true
Expand Down