Last active
August 16, 2024 20:31
-
-
Save ssadler/f2ea11f034dad794e21cc2a133a81842 to your computer and use it in GitHub Desktop.
shader.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// FRAGMENT | |
#include <get_from_texture> | |
precision highp float; | |
//uniform float radius; | |
uniform vec3 color; | |
uniform float thickness; | |
uniform vec2 screenSize; | |
uniform vec2 resolution; | |
varying vec3 vPos; | |
varying mat4 projectionMatrix_; | |
varying mat4 modelViewMatrix_; | |
varying mat4 modelMatrix_; | |
varying vec2 vUv; | |
uniform highp sampler2D radius; | |
flat varying uint vInstanceIndex; | |
#include "include/common.glsl"; | |
float getDist(float thickness, vec3 pos, float radius) { | |
if (abs(length(pos.xy) - radius) < thickness/2.0) { | |
return 1.0; | |
} | |
return 0.0; | |
// Interesting sort of blurred effect | |
//float dist = sdTorus(pos.xzy, vec2(radius, 0.)); | |
//dist = thickness / dist; | |
//return cubicBezier(cb.x, cb.y, cb.z, cb.w, dist); | |
} | |
void main() { | |
float r = getFloatFromTexture(radius, vInstanceIndex); | |
//float d = distanceToCamera(vPos); | |
//float t = 5.0 + d / 2000.0; | |
//float dist = getDist(t, vPos, r); | |
//if (abs(length(vPos.xy) - r) < t*2.0) { | |
// float pixel = d / 1500.0; | |
// dist += getDist(t, vPos+MSAA_0, r); | |
// dist += getDist(t, vPos+MSAA_1, r); | |
// dist += getDist(t, vPos+MSAA_2, r); | |
// dist += getDist(t, vPos+MSAA_3, r); | |
// dist /= 5.0; | |
//} | |
vec4 c = vec4(1.0, 1.0, 1.0, 1.0); // vec4(color, dist); | |
gl_FragColor = c; // vec4(color, getDist(vPos)); | |
} | |
// VERTEX | |
#include <get_from_texture> | |
#include <instanced_pars_vertex> | |
varying mat4 modelViewMatrix_; | |
varying mat4 modelMatrix_; | |
varying mat4 projectionMatrix_; | |
varying vec3 cameraPosition_; | |
varying vec3 vPos; | |
varying vec2 vUv; | |
varying vec3 vDirection; | |
flat varying uint vInstanceIndex; | |
void main() { | |
#include <instanced_vertex> | |
vInstanceIndex = instanceIndex; | |
vUv = uv; | |
// vPos is a misnomer, it's position relative to model center | |
vPos = position; | |
projectionMatrix_ = projectionMatrix; | |
modelViewMatrix_ = modelViewMatrix; | |
modelMatrix_ = modelMatrix; | |
cameraPosition_ = cameraPosition; | |
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment