mirror of
https://github.com/dyuri/repa-shader.git
synced 2025-12-16 11:14:25 +00:00
55 lines
1.5 KiB
HTML
55 lines
1.5 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title><repa-shader> demo</title>
|
|
<script type="module" src="../src/repa-texture.js"></script>
|
|
<script type="module" src="../src/repa-shader.js"></script>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
padding: 0;
|
|
background: repeating-linear-gradient(45deg, #333, #333 10px, #666 10px, #666 20px);
|
|
min-height: 100vh;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
flex-direction: column;
|
|
}
|
|
#fsinput {
|
|
width: 90vw;
|
|
height: 50vh;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<repa-shader id="demoshader" fs-input="fsinput" alpha mouse width=512 height=512>
|
|
<repa-texture src="avatar.png" name="tex_avatar" wrap="mirrored_repeat"></repa-texture>
|
|
<repa-texture t3d name="test3d" filter="nearest"></repa-texture>
|
|
void main() {
|
|
vec2 uv = gl_FragCoord.xy / resolution.xy;
|
|
vec3 col = texture(tex_avatar, uv).rgb;
|
|
|
|
col *= texture(test3d, vec3(uv.xy, mouse.x)).rrr;
|
|
|
|
float dist = distance(uv, mouse.xy);
|
|
float circle = smoothstep(.025, .026, dist) * .5 + .5;
|
|
vec4 acolor = vec4(col * circle, circle);
|
|
outColor = vec4(acolor);
|
|
}
|
|
</repa-shader>
|
|
<div>
|
|
<textarea id="fsinput"></textarea>
|
|
</div>
|
|
<button id="update">Update</button>
|
|
<script>
|
|
const updateButton = document.getElementById('update');
|
|
updateButton.addEventListener('click', () => {
|
|
const fsinput = document.getElementById('fsinput');
|
|
const shader = document.querySelector('repa-shader');
|
|
shader.render(fsinput.value);
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|