New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(layers): ScatterplotLayer uniform buffer #8132
base: master
Are you sure you want to change the base?
Changes from all commits
a3999a2
6b5ce27
e1fffaa
87f578f
8f9e018
4337c8e
df5da65
46c460f
ecbd941
baf4360
49db389
e1691bd
d73400a
7c7729b
1cfa025
61faac7
f8082a1
3436bdd
059146e
ebfcba4
73ce5d2
f5119a6
5f5d233
3b20145
43dbd0d
ac2def1
2f0bd7e
5eb7ed8
90efbc4
edaf8fa
3bfeadc
8fc83f6
359d955
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,46 @@ | |
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
export default `\ | ||
import {ShaderUniformType, glsl} from '@luma.gl/core'; | ||
|
||
export type ScatterplotLayerUniforms = { | ||
// opacity: number; | ||
radiusScale: number; | ||
radiusMinPixels: number; | ||
radiusMaxPixels: number; | ||
lineWidthScale: number; | ||
lineWidthMinPixels: number; | ||
lineWidthMaxPixels: number; | ||
stroked: number; | ||
filled: boolean; | ||
antialiasing: boolean; | ||
billboard: boolean; | ||
radiusUnits: number; | ||
lineWidthUnits: number; | ||
}; | ||
|
||
export const scatterplot: {uniformTypes: Record<string, ShaderUniformType>} = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a little confusing to see this constant referenced in the layer code. Maybe name it |
||
uniformTypes: { | ||
// opacity: 'f32', | ||
radiusScale: 'f32', | ||
radiusMinPixels: 'f32', | ||
radiusMaxPixels: 'f32', | ||
lineWidthScale: 'f32', | ||
lineWidthMinPixels: 'f32', | ||
lineWidthMaxPixels: 'f32', | ||
stroked: 'f32', | ||
filled: 'f32', | ||
antialiasing: 'f32', | ||
billboard: 'f32', | ||
radiusUnits: 'i32', | ||
lineWidthUnits: 'i32' | ||
} | ||
}; | ||
|
||
const SMOOTH_EDGE_RADIUS = 0.5; | ||
|
||
export default glsl`\ | ||
#version 300 es | ||
#define SHADER_NAME scatterplot-layer-vertex-shader | ||
|
||
attribute vec3 positions; | ||
|
@@ -31,56 +70,60 @@ attribute vec4 instanceFillColors; | |
attribute vec4 instanceLineColors; | ||
attribute vec3 instancePickingColors; | ||
|
||
uniform float opacity; | ||
uniform float radiusScale; | ||
uniform float radiusMinPixels; | ||
uniform float radiusMaxPixels; | ||
uniform float lineWidthScale; | ||
uniform float lineWidthMinPixels; | ||
uniform float lineWidthMaxPixels; | ||
uniform float stroked; | ||
uniform bool filled; | ||
uniform bool antialiasing; | ||
uniform bool billboard; | ||
uniform int radiusUnits; | ||
uniform int lineWidthUnits; | ||
|
||
varying vec4 vFillColor; | ||
varying vec4 vLineColor; | ||
varying vec2 unitPosition; | ||
varying float innerUnitRadius; | ||
varying float outerRadiusPixels; | ||
|
||
// Needs to be identical to fragment shader uniforms | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As it needs to be identical, could you define in one place? Derive it from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, though there are some tradeoffs to it. So far it seems the shader linker complains loudly if they are different so it does not seem to be a subtle source of errors. I tried breaking the uniforms into a separate string and injecting it. A minor problem with that is that I use the vscode GLSL syntax highlighter to make these I actually added code for generating uniform declarations from uniform types (in the The high-level question for the TSC is perhaps: how much shader code should be autogenerated? Once one starts down that dark path... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do all the uniforms need to be typed out in both the vertex and fragment shader? It seems unnecessary to have to include uniforms in the vertex shader that only the fragment shader reads and vice-versa I do agree there is a tradeoff between saving time and having shaders that are actually readable in the source There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes I believe so, though more experience may show otherwise. Also we need to see how this works in both GLSL and WGSL. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree with you there. Auto-generation does add a layer of complexity, making it all the more important to have solid debugging tools. I'm all for it, just think we really need to keep an eye on the debugging side of things to make sure everything runs smoothly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, in the spirit of keeping it simple & landing v9 I'm for just typing out the uniforms in full at this stage |
||
uniform scatterplotUniforms { | ||
// float opacity; | ||
float radiusScale; | ||
float radiusMinPixels; | ||
float radiusMaxPixels; | ||
float lineWidthScale; | ||
float lineWidthMinPixels; | ||
float lineWidthMaxPixels; | ||
float stroked; | ||
bool filled; | ||
bool antialiasing; | ||
bool billboard; | ||
int radiusUnits; | ||
int lineWidthUnits; | ||
} scatterplot; | ||
|
||
uniform float opacity; | ||
|
||
void main(void) { | ||
geometry.worldPosition = instancePositions; | ||
|
||
// Multiply out radius and clamp to limits | ||
outerRadiusPixels = clamp( | ||
project_size_to_pixel(radiusScale * instanceRadius, radiusUnits), | ||
radiusMinPixels, radiusMaxPixels | ||
project_size_to_pixel(scatterplot.radiusScale * instanceRadius, scatterplot.radiusUnits), | ||
scatterplot.radiusMinPixels, scatterplot.radiusMaxPixels | ||
); | ||
|
||
// Multiply out line width and clamp to limits | ||
float lineWidthPixels = clamp( | ||
project_size_to_pixel(lineWidthScale * instanceLineWidths, lineWidthUnits), | ||
lineWidthMinPixels, lineWidthMaxPixels | ||
project_size_to_pixel(scatterplot.lineWidthScale * instanceLineWidths, scatterplot.lineWidthUnits), | ||
scatterplot.lineWidthMinPixels, scatterplot.lineWidthMaxPixels | ||
); | ||
|
||
// outer radius needs to offset by half stroke width | ||
outerRadiusPixels += stroked * lineWidthPixels / 2.0; | ||
outerRadiusPixels += scatterplot.stroked * lineWidthPixels / 2.0; | ||
|
||
// Expand geometry to accomodate edge smoothing | ||
float edgePadding = antialiasing ? (outerRadiusPixels + SMOOTH_EDGE_RADIUS) / outerRadiusPixels : 1.0; | ||
// Expand geometry to accommodate edge smoothing | ||
float edgePadding = scatterplot.antialiasing ? (outerRadiusPixels + SMOOTH_EDGE_RADIUS) / outerRadiusPixels : 1.0; | ||
|
||
// position on the containing square in [-1, 1] space | ||
unitPosition = edgePadding * positions.xy; | ||
geometry.uv = unitPosition; | ||
geometry.pickingColor = instancePickingColors; | ||
|
||
innerUnitRadius = 1.0 - stroked * lineWidthPixels / outerRadiusPixels; | ||
innerUnitRadius = 1.0 - scatterplot.stroked * lineWidthPixels / outerRadiusPixels; | ||
|
||
if (billboard) { | ||
if (scatterplot.billboard) { | ||
gl_Position = project_position_to_clipspace(instancePositions, instancePositions64Low, vec3(0.0), geometry.position); | ||
DECKGL_FILTER_GL_POSITION(gl_Position, geometry); | ||
vec3 offset = edgePadding * positions * outerRadiusPixels; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More restrictive type?
0 | 1 | 2