clip_shared.glsl (2839B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #include rect,render_task,transform 6 7 #ifdef WR_VERTEX_SHADER 8 9 PER_INSTANCE in vec4 aClipDeviceArea; 10 PER_INSTANCE in vec4 aClipOrigins; 11 PER_INSTANCE in float aDevicePixelScale; 12 PER_INSTANCE in ivec2 aTransformIds; 13 14 struct ClipMaskInstanceCommon { 15 RectWithEndpoint sub_rect; 16 vec2 task_origin; 17 vec2 screen_origin; 18 float device_pixel_scale; 19 int clip_transform_id; 20 int prim_transform_id; 21 }; 22 23 ClipMaskInstanceCommon fetch_clip_item_common() { 24 ClipMaskInstanceCommon cmi; 25 26 cmi.sub_rect = RectWithEndpoint(aClipDeviceArea.xy, aClipDeviceArea.zw); 27 cmi.task_origin = aClipOrigins.xy; 28 cmi.screen_origin = aClipOrigins.zw; 29 cmi.device_pixel_scale = aDevicePixelScale; 30 cmi.clip_transform_id = aTransformIds.x; 31 cmi.prim_transform_id = aTransformIds.y; 32 33 return cmi; 34 } 35 36 struct ClipVertexInfo { 37 vec4 local_pos; 38 RectWithEndpoint clipped_local_rect; 39 }; 40 41 // The transformed vertex function that always covers the whole clip area, 42 // which is the intersection of all clip instances of a given primitive 43 ClipVertexInfo write_clip_tile_vertex(RectWithEndpoint local_clip_rect, 44 Transform prim_transform, 45 Transform clip_transform, 46 RectWithEndpoint sub_rect, 47 vec2 task_origin, 48 vec2 screen_origin, 49 float device_pixel_scale) { 50 vec2 device_pos = screen_origin + mix(sub_rect.p0, sub_rect.p1, aPosition.xy); 51 vec2 world_pos = device_pos / device_pixel_scale; 52 53 vec4 pos = prim_transform.m * vec4(world_pos, 0.0, 1.0); 54 pos.xyz /= pos.w; 55 56 vec4 p = get_node_pos(pos.xy, clip_transform); 57 vec4 local_pos = p * pos.w; 58 59 //TODO: Interpolate in clip space, where "local_pos.w" contains 60 // the W of the homogeneous transform *from* clip space into the world. 61 // float interpolate_w = 1.0 / local_pos.w; 62 // This is problematic today, because the W<=0 hemisphere is going to be 63 // clipped, while we currently want this shader to fill out the whole rect. 64 // We can therefore simplify this when the clip construction is rewritten 65 // to only affect the areas touched by a clip. 66 vec4 vertex_pos = vec4( 67 task_origin + mix(sub_rect.p0, sub_rect.p1, aPosition.xy), 68 0.0, 69 1.0 70 ); 71 72 gl_Position = uTransform * vertex_pos; 73 74 rectangle_aa_vertex(vec4(local_clip_rect.p0, local_clip_rect.p1)); 75 76 ClipVertexInfo vi = ClipVertexInfo(local_pos, local_clip_rect); 77 return vi; 78 } 79 80 #endif //WR_VERTEX_SHADER