The showcase prompt, round 3, Gemini 4 Carbon
agent (cont.)
+51:34read_file{"EndLine":2600,"Path":"~/run/index.html","StartLine":1601}
input
{ "EndLine": 2600, "Path": "~/run/index.html", "StartLine": 1601 }result, 801 lines
Showing lines 1601-2400 of 3164 1601: out vec2 vUV; 1602: void main() { 1603: vec2 pos = vec2((gl_VertexID << 1) & 2, gl_VertexID & 2); 1604: vUV = pos; 1605: gl_Position = vec4(pos * 2.0 - 1.0, 0.0, 1.0); 1606: } 1607: `; 1608: 1609: const BLOOM_FS = `#version 300 es 1610: precision highp float; 1611: in vec2 vUV; 1612: uniform sampler2D uTex; 1613: uniform vec2 uTexel; 1614: uniform float uRadius; 1615: out vec4 fragColor; 1616: void main() { 1617: vec2 d = uTexel * uRadius; 1618: vec3 s = texture(uTex, vUV).rgb * 0.28; 1619: s += texture(uTex, vUV + vec2( d.x, d.y)).rgb * 0.18; 1620: s += texture(uTex, vUV + vec2(-d.x, d.y)).rgb * 0.18; 1621: s += texture(uTex, vUV + vec2( d.x, -d.y)).rgb * 0.18; 1622: s += texture(uTex, vUV + vec2(-d.x, -d.y)).rgb * 0.18; 1623: fragColor = vec4(s, 1.0); 1624: } 1625: `; 1626: 1627: // ---------------------------------------------------------------------------- 1628: // PASS 3A: STUDIO BACKGROUND + OBSIDIAN STAGE FLOOR + HDR CAUSTIC PROJECTION 1629: // ---------------------------------------------------------------------------- 1630: const STAGE_VS = `#version 300 es 1631: precision highp float; 1632: layout(location = 0) in vec3 aPos; 1633: uniform mat4 uVP; 1634: out vec3 vWorldPos; 1635: void main() { 1636: vWorldPos = aPos; 1637: gl_Position = uVP * vec4(aPos, 1.0); 1638: } 1639: `; 1640: 1641: const STAGE_FS = `#version 300 es 1642: precision highp float; 1643: in vec3 vWorldPos; 1644: uniform sampler2D uCausticTex; 1645: uniform sampler2D uBloomTex; 1646: uniform sampler2D uTargetTex; 1647: uniform vec3 uCamPos; 1648: uniform vec3 uLightWorld; 1649: uniform float uFocalZ; 1650: uniform float uCausticScale; 1651: uniform int uCompareMask; 1652: 1653: out vec4 fragColor; 1654: 1655: float hash21(vec2 p) { 1656: p = fract(p * vec2(123.34, 456.21)); 1657: p += dot(p, p + 45.32); 1658: return fract(p.x * p.y); 1659: } 1660: 1661: float smoothGrain(vec2 p) { 1662: vec2 i = floor(p), f = fract(p); 1663: f = f * f * (3.0 - 2.0 * f); 1664: float a = hash21(i), b = hash21(i + vec2(1.0, 0.0)); 1665: float c = hash21(i + vec2(0.0, 1.0)), d = hash21(i + vec2(1.0, 1.0)); 1666: return mix(mix(a, b, f.x), mix(c, d, f.x), f.y); 1667: } 1668: 1669: void main() { 1670: vec2 optP = vec2(vWorldPos.x, -vWorldPos.z); 1671: const float STAGE_EXTENT = 1.45; 1672: vec2 causticUV = optP / (2.0 * STAGE_EXTENT) + 0.5; 1673: 1674: // Smooth honed black basalt optical stage 1675: float rStage = length(vWorldPos.xz); 1676: float grain = (smoothGrain(vWorldPos.xz * 85.0) - 0.5) * 0.005; 1677: vec3 baseSlate = vec3(0.015, 0.017, 0.024) + grain; 1678: 1679: vec3 L = normalize(uLightWorld - vWorldPos); 1680: vec3 V = normalize(uCamPos - vWorldPos); 1681: vec3 H = normalize(L + V); 1682: float spec = pow(max(0.0, H.y), 48.0) * 0.022; 1683: vec2 boxD = abs(optP) - vec2(1.0); 1684: float frameBorder = abs(max(boxD.x, boxD.y)); 1685: baseSlate += vec3(1.0, 0.88, 0.72) * spec * smoothstep(-0.15, 0.45, max(boxD.x, boxD.y)); 1686: 1687: // Calibrated hairline 100mm optical bench reticle & millimeter ticks 1688: float borderLine = exp(-pow(frameBorder / 0.0042, 2.0)) * step(max(abs(optP.x), abs(optP.y)), 1.03); 1689: float tickMarks = 0.0; 1690: if (abs(frameBorder - 0.022) < 0.018 && max(abs(optP.x), abs(optP.y)) < 1.03) { 1691: float c = (abs(optP.x) > abs(optP.y)) ? optP.y : optP.x; 1692: tickMarks = exp(-pow(sin(c * 3.14159265 * 10.0) / 0.12, 2.0)) * 0.35; 1693: } 1694: vec3 reticleCol = vec3(0.34, 0.38, 0.48) * (borderLine * 0.42 + tickMarks * 0.22); 1695: 1696: // Sample live raytraced HDR Caustics + Dual-Kawase halation 1697: vec3 causticRaw = vec3(0.0); 1698: vec3 bloomRaw = vec3(0.0); 1699: if (causticUV.x > 0.002 && causticUV.x < 0.998 && causticUV.y > 0.002 && causticUV.y < 0.998) { 1700: causticRaw = texture(uCausticTex, causticUV).rgb * uCausticScale; 1701: bloomRaw = texture(uBloomTex, causticUV).rgb * uCausticScale; 1702: } 1703: 1704: // Rich contrast curve so evacuated dark regions stay deep obsidian while concentrated cusps blaze 1705: vec3 crispCaustic = pow(max(causticRaw, 0.0), vec3(1.16)) * 1.35; 1706: vec3 lightDeposit = crispCaustic + pow(max(bloomRaw, 0.0), vec3(1.15)) * 0.24; 1707: 1708: if (uCompareMask == 1 && abs(optP.x) < 1.0 && abs(optP.y) < 1.0) { 1709: if (optP.x < 0.0) { 1710: vec2 tUV = optP * 0.5 + 0.5; 1711: float targVal = texture(uTargetTex, tUV).r; 1712: float maskTrans = clamp((targVal - 0.032) / 1.15, 0.0, 1.0); 1713: float directSun = 0.055; // 1.0x unconcentrated incident flux (92% blocked elsewhere!) 1714: lightDeposit = vec3(1.0, 0.85, 0.62) * (directSun * maskTrans); 1715: } 1716: float splitLine = exp(-pow(optP.x / 0.0038, 2.0)); 1717: reticleCol += vec3(0.95, 0.74, 0.45) * splitLine * 0.75; 1718: } 1719: 1720: vec3 col = baseSlate + reticleCol + lightDeposit; 1721: float vig = smoothstep(3.4, 1.30, rStage); 1722: col *= vig; 1723: 1724: col = (col * (2.51 * col + 0.03)) / (col * (2.43 * col + 0.59) + 0.14); 1725: col = pow(max(col, 0.0), vec3(1.0 / 2.2)); 1726: fragColor = vec4(col, 1.0); 1727: } 1728: `; 1729: 1730: // ---------------------------------------------------------------------------- 1731: // PASS 3B: 3D WATERTIGHT SCULPTED OPTICAL GLASS BLOCK 1732: // Uses Exact Analytical 3D Ray-Plane Refraction onto Stage y=0! 1733: // ---------------------------------------------------------------------------- 1734: const GLASS_VS = `#version 300 es 1735: precision highp float; 1736: layout(location = 0) in vec3 aGridPos; 1737: layout(location = 1) in vec3 aWallNormal; 1738: 1739: uniform mat4 uVP; 1740: uniform float uFocalZ; 1741: uniform float uTGlass; 1742: 1743: ${GLSL_BSPLINE_HEIGHT} 1744: 1745: out vec3 vWorldPos; 1746: out vec3 vNormal; 1747: out vec2 vOptP; 1748: out float vHeight; 1749: out float vFaceType; 1750: out float vCurvature; 1751: 1752: void main() { 1753: vec2 p = aGridPos.xy; 1754: float face = aGridPos.z; 1755: vec3 hGrad = sampleGlassSpline(p); 1756: // Estimate local mean curvature for subtle caustics-in-glass sheen 1757: vec3 hR = sampleGlassSpline(p + vec2(0.015, 0.0)); 1758: vec3 hU = sampleGlassSpline(p + vec2(0.0, 0.015)); 1759: vCurvature = (hR.y - hGrad.y) + (hU.z - hGrad.z); 1760: 1761: float yWorld = 0.0; 1762: vec3 nWorld = vec3(0.0, 1.0, 0.0); 1763: 1764: if (face < 0.5) { 1765: yWorld = uFocalZ + hGrad.x; 1766: nWorld = normalize(vec3(hGrad.y, -1.0, -hGrad.z)); 1767: } else if (face < 1.5) { 1768: yWorld = uFocalZ + uTGlass; 1769: nWorld = vec3(0.0, 1.0, 0.0); 1770: } else { 1771: float isTop = aWallNormal.y; 1772: yWorld = (isTop > 0.5) ? (uFocalZ + uTGlass) : (uFocalZ + hGrad.x); 1773: nWorld = normalize(vec3(aWallNormal.x, 0.0, aWallNormal.z)); 1774: } 1775: 1776: vec3 worldPos = vec3(p.x, yWorld, -p.y); 1777: vWorldPos = worldPos; 1778: vNormal = nWorld; 1779: vOptP = p; 1780: vHeight = hGrad.x; 1781: vFaceType = face; 1782: gl_Position = uVP * vec4(worldPos, 1.0); 1783: } 1784: `; 1785: 1786: const GLASS_FS = `#version 300 es 1787: precision highp float; 1788: in vec3 vWorldPos; 1789: in vec3 vNormal; 1790: in vec2 vOptP; 1791: in float vHeight; 1792: in float vFaceType; 1793: in float vCurvature; 1794: 1795: uniform sampler2D uCausticTex; 1796: uniform sampler2D uBloomTex; 1797: uniform float uCausticScale; 1798: uniform vec3 uCamPos; 1799: uniform vec3 uLightWorld; 1800: uniform float uBaseIOR; 1801: uniform vec3 uGlassTint; 1802: uniform int uShowInterf; 1803: 1804: out vec4 fragColor; 1805: 1806: vec3 sampleStageAtWorldXZ(vec2 xz) { 1807: vec2 optP = vec2(xz.x, -xz.y); 1808: const float STAGE_EXTENT = 1.45; 1809: vec2 cUV = optP / (2.0 * STAGE_EXTENT) + 0.5; 1810: vec3 base = vec3(0.018, 0.022, 0.032); 1811: vec2 boxD = abs(optP) - vec2(1.0); 1812: float borderLine = exp(-pow(abs(max(boxD.x, boxD.y)) / 0.005, 2.0)) * step(max(abs(optP.x), abs(optP.y)), 1.03); 1813: base += vec3(0.32, 0.36, 0.46) * borderLine * 0.4; 1814: if (cUV.x > 0.002 && cUV.x < 0.998 && cUV.y > 0.002 && cUV.y < 0.998) { 1815: vec3 cRaw = texture(uCausticTex, cUV).rgb * uCausticScale; 1816: vec3 bRaw = texture(uBloomTex, cUV).rgb * uCausticScale; 1817: base += pow(max(cRaw, 0.0), vec3(1.16)) * 1.35 + pow(max(bRaw, 0.0), vec3(1.15)) * 0.24; 1818: } 1819: base *= smoothstep(3.4, 1.3, length(xz)); 1820: return base; 1821: } 1822: 1823: void main() { 1824: vec3 N = normalize(gl_FrontFacing ? vNormal : -vNormal); 1825: vec3 V = normalize(uCamPos - vWorldPos); 1826: vec3 I = -V; 1827: 1828: // Exact 3D chromatic view-ray refraction onto the y = 0 stage below (or dark studio horizon) 1829: vec3 rayR = refract(I, N, 1.0 / (uBaseIOR - 0.018)); 1830: vec3 rayG = refract(I, N, 1.0 / uBaseIOR); 1831: vec3 rayB = refract(I, N, 1.0 / (uBaseIOR + 0.018)); 1832: 1833: vec3 refrLinear = vec3(0.022, 0.028, 0.042); 1834: if (rayG.y < -0.04) { 1835: vec2 xzR = vWorldPos.xz + rayR.xz * (-vWorldPos.y / min(-0.04, rayR.y)); 1836: vec2 xzG = vWorldPos.xz + rayG.xz * (-vWorldPos.y / rayG.y); 1837: vec2 xzB = vWorldPos.xz + rayB.xz * (-vWorldPos.y / min(-0.04, rayB.y)); 1838: refrLinear = vec3( 1839: sampleStageAtWorldXZ(xzR).r, 1840: sampleStageAtWorldXZ(xzG).g, 1841: sampleStageAtWorldXZ(xzB).b 1842: ); 1843: } else { 1844: // Grazing internal reflection of studio softbox & warm lamp glow 1845: float horizon = smoothstep(-0.1, 0.5, rayG.y); 1846: refrLinear = mix(vec3(0.04, 0.07, 0.10), vec3(0.14, 0.20, 0.28), horizon); 1847: } 1848: 1849: // Beer-Lambert optical crystal tint + subtle polished aqua-emerald ground bevel glow 1850: float cosTheta = max(0.02, dot(N, V)); 1851: float pathLen = (vFaceType > 1.5) ? 0.65 : (0.16 / max(0.22, cosTheta)); 1852: vec3 absorb = pow(uGlassTint, vec3(pathLen * 2.2)); 1853: refrLinear *= absorb; 1854: 1855: // Subtle internal light-scatter glow where the overhead lamp illuminates sculpted glass curvature 1856: vec3 L = normalize(uLightWorld - vWorldPos); 1857: float transGlow = pow(max(0.0, dot(-L, V)), 5.0) * 0.08 + abs(vCurvature) * 0.012; 1858: refrLinear += vec3(0.85, 0.94, 1.0) * uGlassTint * transGlow; 1859: 1860: if (vFaceType > 1.5) { 1861: // Frosted/polished optical slab perimeter edge catchlight 1862: float sideLight = 0.45 + 0.55 * abs(dot(N, normalize(vec3(1.0, 0.4, 0.8)))); 1863: refrLinear += vec3(0.07, 0.15, 0.18) * uGlassTint * sideLight; 1864: } 1865: 1866: // Schlick Fresnel reflection from overhead point lamp & dual studio softboxes 1867: float r0 = pow((uBaseIOR - 1.0) / (uBaseIOR + 1.0), 2.0); 1868: float fresnel = r0 + (1.0 - r0) * pow(1.0 - cosTheta, 5.0); 1869: 1870: vec3 H = normalize(L + V); 1871: float specLamp = pow(max(0.0, dot(N, H)), 220.0) * 2.4 + pow(max(0.0, dot(N, H)), 26.0) * 0.18; 1872: vec3 R_refl = reflect(I, N); 1873: float box1 = smoothstep(0.25, 0.85, R_refl.y) * smoothstep(-0.6, 0.4, R_refl.x); 1874: float box2 = smoothstep(0.10, 0.70, R_refl.y) * smoothstep(0.6, -0.3, R_refl.z) * 0.6; 1875: vec3 envLinear = vec3(0.20, 0.26, 0.35) * (box1 + box2) + vec3(1.0, 0.88, 0.68) * specLamp; 1876: 1877: // Crisp diamond-chamfer bevel highlight around [-1, 1]^2 glass edge 1878: vec2 edgeD = abs(vOptP); 1879: float bevel = smoothstep(0.980, 0.998, max(edgeD.x, edgeD.y)); 1880: 1881: vec3 col = mix(refrLinear, envLinear, clamp(fresnel * 1.35 + 0.05, 0.05, 0.92)); 1882: col += vec3(0.22, 0.34, 0.40) * bevel * 0.55; 1883: 1884: // Optional Mach-Zehnder Laser Interferogram (micron thickness fringes cos(phase)) 1885: if (uShowInterf == 1 && vFaceType < 1.5) { 1886: float phase = vHeight * 280.0; 1887: float fringe = pow(0.5 + 0.5 * cos(phase), 2.6); 1888: vec3 interfCol = mix(vec3(0.01, 0.08, 0.12), vec3(0.32, 0.95, 0.86), fringe); 1889: col = mix(col, col * 0.35 + interfCol * 0.55, 0.68); 1890: } 1891: 1892: // Match stage ACES filmic tone-mapping + gamma 1893: col = (col * (2.51 * col + 0.03)) / (col * (2.43 * col + 0.59) + 0.14); 1894: col = pow(max(col, 0.0), vec3(1.0 / 2.2)); 1895: fragColor = vec4(col, 1.0); 1896: } 1897: `; 1898: 1899: // ---------------------------------------------------------------------------- 1900: // PASS 3C: DIAGNOSTIC 3D LINES (Snell Ray Sheet, Optimal Transport Grid, Lamp Cone) 1901: // ---------------------------------------------------------------------------- 1902: const LINE_VS = `#version 300 es 1903: precision highp float; 1904: layout(location = 0) in vec3 aPos; 1905: layout(location = 1) in vec4 aCol; 1906: uniform mat4 uVP; 1907: out vec4 vCol; 1908: void main() { 1909: vCol = aCol; 1910: gl_Position = uVP * vec4(aPos, 1.0); 1911: } 1912: `; 1913: 1914: const LINE_FS = `#version 300 es 1915: precision highp float; 1916: in vec4 vCol; 1917: out vec4 fragColor; 1918: void main() { 1919: fragColor = vCol; 1920: } 1921: `; 1922: 1923: // 3D Point Lamp Billboard Glow Shader 1924: const LAMP_VS = `#version 300 es 1925: precision highp float; 1926: uniform mat4 uVP; 1927: uniform vec3 uLampPos; 1928: uniform vec3 uCamRight; 1929: uniform vec3 uCamUp; 1930: uniform float uSize; 1931: out vec2 vQuad; 1932: void main() { 1933: vec2 corners[4] = vec2[4](vec2(-1,-1), vec2(1,-1), vec2(-1,1), vec2(1,1)); 1934: int idx[6] = int[6](0, 1, 2, 2, 1, 3); 1935: vec2 q = corners[idx[gl_VertexID]]; 1936: vQuad = q; 1937: vec3 world = uLampPos + (uCamRight * q.x + uCamUp * q.y) * uSize; 1938: gl_Position = uVP * vec4(world, 1.0); 1939: } 1940: `; 1941: 1942: const LAMP_FS = `#version 300 es 1943: precision highp float; 1944: in vec2 vQuad; 1945: uniform float uFocusLock; 1946: out vec4 fragColor; 1947: void main() { 1948: float r = length(vQuad); 1949: if (r > 1.0) discard; 1950: float core = exp(-r * r * 38.0); 1951: float halo = exp(-r * r * 5.2) * 0.55 + pow(max(0.0, 1.0 - r), 3.0) * 0.22; 1952: vec3 col = vec3(1.0, 0.94, 0.82) * core * 1.4 + mix(vec3(1.0, 0.74, 0.38), vec3(0.65, 0.92, 1.0), uFocusLock * 0.25) * halo; 1953: fragColor = vec4(col, 1.0); 1954: } 1955: `; 1956: 1957: const progCaustic = createProgram(CAUSTIC_VS, CAUSTIC_FS); 1958: const progBloom = createProgram(QUAD_VS, BLOOM_FS); 1959: const progStage = createProgram(STAGE_VS, STAGE_FS); 1960: const progGlass = createProgram(GLASS_VS, GLASS_FS); 1961: const progLine = createProgram(LINE_VS, LINE_FS); 1962: const progLamp = createProgram(LAMP_VS, LAMP_FS); 1963: 1964: // ============================================================================ 1965: // 7. GPU BUFFERS, TEXTURES & FRAMEBUFFERS 1966: // ============================================================================ 1967: // 1) Heightfield R32F Texture (256x256) + Target R32F Texture (256x256) 1968: const heightTex = gl.createTexture(); 1969: gl.bindTexture(gl.TEXTURE_2D, heightTex); 1970: gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); 1971: gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); 1972: gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); 1973: gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); 1974: gl.texImage2D(gl.TEXTURE_2D, 0, gl.R32F, N_GRID, N_GRID, 0, gl.RED, gl.FLOAT, new Float32Array(N_GRID * N_GRID)); 1975: 1976: const targetTex = gl.createTexture(); 1977: gl.bindTexture(gl.TEXTURE_2D, targetTex); 1978: gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, extLinearFloat ? gl.LINEAR : gl.NEAREST); 1979: gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, extLinearFloat ? gl.LINEAR : gl.NEAREST); 1980: gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); 1981: gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); 1982: gl.texImage2D(gl.TEXTURE_2D, 0, gl.R32F, N_GRID, N_GRID, 0, gl.RED, gl.FLOAT, new Float32Array(N_GRID * N_GRID)); 1983: 1984: // 2) Caustic FBO (1024x1024 RGBA16F HDR or RGBA8 scaled fallback) + Bloom FBOs (512x512) 1985: const CAUSTIC_RES = 1024; 1986: function createFBO(w, h, useFloat) { 1987: const tex = gl.createTexture(); 1988: gl.bindTexture(gl.TEXTURE_2D, tex); 1989: const filter = (!useFloat || extLinearFloat) ? gl.LINEAR : gl.NEAREST; 1990: gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filter); 1991: gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filter); 1992: gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); 1993: gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); 1994: if (useFloat) { 1995: gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA16F, w, h, 0, gl.RGBA, gl.HALF_FLOAT, null); 1996: } else { 1997: gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, w, h, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); 1998: } 1999: const fbo = gl.createFramebuffer();401 more lines not shown.