From 21b7668a7ab3c136c6edcc39c404b7938d61b97b Mon Sep 17 00:00:00 2001 From: Min Kang Date: Thu, 12 Nov 2026 19:00:58 +0000 Subject: [PATCH] Prevent longitude seams from selecting coarse texture mipmaps --- apps/web/js/illustrativeAppearance.js | 2 +- apps/web/js/orreryShaders.js | 16 +++++++++++++--- tools/planet_appearance_validation.mjs | 14 +++++++++++--- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/apps/web/js/illustrativeAppearance.js b/apps/web/js/illustrativeAppearance.js index 66d4bf9b..38bd66f5 100644 --- a/apps/web/js/illustrativeAppearance.js +++ b/apps/web/js/illustrativeAppearance.js @@ -38,7 +38,7 @@ export const VENUS_ATMOSPHERE_SHELL_GLSL = ` if(u_mode==4){ float uu=0.5+atan(p.y,p.x)*0.1591549431; float vv=acos(clamp(p.z,-1.0,1.0))*0.3183098862; - vec3 clouds=decodeSRGB(texture(u_tex,vec2(uu,vv)).rgb); + vec3 clouds=decodeSRGB(equirectangularSample(u_tex,p,vec2(uu,vv)).rgb); float sun=max(dot(N,normalize(u_light)),0.0); float cover=smoothstep(0.05,0.22,sun); float ndv=clamp(dot(N,V),0.0,1.0); diff --git a/apps/web/js/orreryShaders.js b/apps/web/js/orreryShaders.js index c0e2bbf2..a564928b 100644 --- a/apps/web/js/orreryShaders.js +++ b/apps/web/js/orreryShaders.js @@ -176,6 +176,16 @@ ${ATMOSPHERE_GLSL} ${TERRAIN_SHADOW_GLSL} ${RING_TRANSPORT_GLSL} ${NOISE} +// Display maps wrap at the back meridian. Differentiate longitude along the +// local tangent so the 1-to-0 UV jump cannot select a whole-map mip level. +// Keep ordinary mip filtering and the source pixels on both sides of the join. +vec4 equirectangularSample(sampler2D source,vec3 p,vec2 uv){ + vec2 tangent=vec2(-p.y,p.x); + float gain=0.1591549431/max(dot(p.xy,p.xy),1e-8); + vec2 dx=vec2(dot(tangent,dFdx(p.xy))*gain,dFdx(uv.y)); + vec2 dy=vec2(dot(tangent,dFdy(p.xy))*gain,dFdy(uv.y)); + return textureGrad(source,uv,dx,dy); +} // Every registered layer of a body shares one source grid. main computes this // once per fragment (u, v, source latitude) and passes it to each lookup, so the // same atan pair is not re-evaluated for every layer and coverage test. @@ -353,7 +363,7 @@ ${VENUS_ATMOSPHERE_SHELL_GLSL} col=u_base*mix(vec3(1.0),material,referenceCoverage(referenceGridValue,mapped)); } else if(u_useTex==1&&u_texMode==0){ - col=texture(u_tex,vec2(uu,vv)).rgb; + col=equirectangularSample(u_tex,p,vec2(uu,vv)).rgb; if(u_illustrativeLinear==1) col=u_saturnLook==1 ? pow(col,vec3(2.2)) : decodeSRGB(col); } else if(u_useTex==1&&u_texMode==2){ // real USGS moon mosaic @@ -365,7 +375,7 @@ ${VENUS_ATMOSPHERE_SHELL_GLSL} // The clamp stops the brightest few texels of a low-mean map from blowing out. vec3 avg=textureLod(u_tex,vec2(0.5,0.5),20.0).rgb; float mean=max(dot(avg,vec3(0.299,0.587,0.114)),0.02); - float here=dot(texture(u_tex,vec2(uu,vv)).rgb,vec3(0.299,0.587,0.114)); + float here=dot(equirectangularSample(u_tex,p,vec2(uu,vv)).rgb,vec3(0.299,0.587,0.114)); // The 0.6 exponent softens the map's OWN contrast, and it is load-bearing rather than // cosmetic. Each browse rendering is stretched independently — Callisto's sits at mean // 0.18 with a full-scale tail, Europa's at 0.57 with a narrow one — so at full strength @@ -464,7 +474,7 @@ ${VENUS_ATMOSPHERE_SHELL_GLSL} // should lead, with the noise surviving only as surface texture under it. if(u_useTex==1&&u_texMode==1){ col=mix(col,u_base,0.55); - col*=texture(u_tex,vec2(uu,vv)).rgb*2.0; + col*=equirectangularSample(u_tex,p,vec2(uu,vv)).rgb*2.0; } // Legacy fallback/material recipes are display RGB. Only the enabled optical // path opts them into linear transport; historical disabled uniforms retain diff --git a/tools/planet_appearance_validation.mjs b/tools/planet_appearance_validation.mjs index a409fc05..773ff851 100644 --- a/tools/planet_appearance_validation.mjs +++ b/tools/planet_appearance_validation.mjs @@ -54,6 +54,8 @@ const fixtures = new Map([ // Matching dark edges and a bright interior: a false coarse mip at the // longitude wrap becomes a bright strip in the actual moon contrast mode. ["/spatial-seam.png", fixture(64, 32, x => x < 4 || x >= 60 ? [32,32,32,255] : [224,224,224,255])], + // Subpixel alternating texels must retain mip smoothing after the wrap fix. + ["/checker.png", fixture(1024, 512, (x,y) => [...Array(3).fill((x+y)%2 ? 255 : 0),255])], // A geographically bounded dark-red deposit against brighter terrain tests // valid dark RGB and the uncompressed part of the relative-contrast display. ["/color-deposits.png", fixture(64, 32, x => x < 8 ? [48,12,6,255] : [192,192,192,255])], @@ -154,7 +156,7 @@ async function run() { // Coordinate-gradient probes use nearest to make source texel identity explicit. // Quadrants and seam exercise the renderer's actual linear/mipmap upload path. const maskedPhoto = ["/transparent.png", "/half-white.png", "/alpha-edge.png", "/color-alpha-edge.png"].includes(name); - textures[name] = textureFactory(image, true, !["/quadrants.png", "/seam.png", "/spatial-seam.png", "/color-deposits.png", "/alpha-edge.png", "/color-alpha-edge.png"].includes(name), maskedPhoto); + textures[name] = textureFactory(image, true, !["/quadrants.png", "/seam.png", "/spatial-seam.png", "/checker.png", "/color-deposits.png", "/alpha-edge.png", "/color-alpha-edge.png"].includes(name), maskedPhoto); uploadPremultiplyStates.push({name, expected:maskedPhoto, actual:gl.getParameter(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL)}); if (name === "/quadrants.png") textures.flipped = flippedFactory(image, true, false); if (['/opaque-edge.png','/saturated-edge.png'].includes(name)) { @@ -180,6 +182,7 @@ async function run() { gl.bindFramebuffer(gl.FRAMEBUFFER,options.linearOutput ? linearTarget : null); i('u_linearOutput',options.linearOutput ? 1 : 0); i('u_textureLinear',options.textureLinear ? 1 : 0); + i('u_illustrativeLinear',options.illustrative ? 1 : 0); const p = options.position || [0, 1, 1], e = .0001; const vertices = [[-1,-1], [1,-1], [-1,1], [-1,1], [1,-1], [1,1]]; gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices.flatMap(([x,y]) => [p[0]+e*x,p[1]+e*y,p[2]])), gl.STATIC_DRAW); @@ -314,13 +317,18 @@ async function run() { for (const side of [-1,1]) check(`continuous source seam side ${side}`, await probe({position:[-1,side*.001,0],texture:"/seam.png"}), [40,120,220,255]); const spatialCases = [ + ['display map',0,'/seam.png',[40,120,220,255]], + ['illustrative planet',0,'/seam.png',[40,120,220,255],undefined,{illustrative:true}], + ['minified display map',0,'/checker.png',[128,128,128,255]], + ['legacy moon',2,'/spatial-seam.png',rgba([.2,.3,.4].map(c=>255*c*(32/200)**.6))], + ['Venus cloud shell',0,'/seam.png',[40,120,220,97],undefined,{mode:4,camera:[0,0,1e6]}], ['registered colour',3,'/seam.png',[40,120,220,255]], ['registered moon',4,'/spatial-seam.png',rgba([.2,.3,.4].map(c=>255*c*(32/200)**.6))], ['registered color moon',5,'/seam.png',rgba([40/220,120/220,1].map(c=>255*.6*c)),[.6,.6,.6]], ]; - for (const [name,texMode,texture,expected,base] of spatialCases) { + for (const [name,texMode,texture,expected,base,extra] of spatialCases) { for (const crossing of [false,true]) { - const spatial = await pairedProbe('spatialSeamProbe',{texMode,texture,crossing,base}); + const spatial = await pairedProbe('spatialSeamProbe',{texMode,texture,crossing,base,...extra}); check(`${name} spatial ${crossing ? 'longitude-wrap' : 'non-wrapping'} patch retains edge texels`, spatial.pixels, Array.from({length:spatial.width*spatial.height},()=>expected).flat(), 2); }