Skip to content

Instantly share code, notes, and snippets.

@ramboldio
Last active November 8, 2022 12:45
Show Gist options
  • Save ramboldio/828bac8855f20b8ed939aa45027eeb72 to your computer and use it in GitHub Desktop.
Save ramboldio/828bac8855f20b8ed939aa45027eeb72 to your computer and use it in GitHub Desktop.
Three.js / WebGL Custom texture shader
<script type="x-shader/x-vertex" id="vertexshader">
// switch on high precision floats
#ifdef GL_ES
precision highp float;
#endif
varying vec2 texcoord;
void main()
{
gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0);
texcoord = uv;
}
</script>
<script type="x-shader/x-fragment" id="fragmentshader">
#ifdef GL_ES
precision highp float;
#endif
varying vec2 texcoord;
uniform sampler2D u_texture;
void main()
{
/* Set color of the fragment */
gl_FragColor = texture2D(u_texture, texcoord);
}
</script>
@claytonrothschild
Copy link

Thanks, this really helped me on a project I am working on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment