Skip to content
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

GRL - instancing support #14460

Merged
merged 8 commits into from Oct 25, 2023
Expand Up @@ -372,7 +372,7 @@ export class GreasedLinePluginMaterial extends MaterialPluginBase implements IGr
grlCounters = grl_nextAndCounters.w;
mat4 grlMatrix = viewProjection * world;
mat4 grlMatrix = viewProjection * finalWorld;
vec4 grlFinalPosition = grlMatrix * vec4( positionUpdated , 1.0 );
vec4 grlPrevPos = grlMatrix * vec4( grlPrevious + grlPositionOffset, 1.0 );
vec4 grlNextPos = grlMatrix * vec4( grlNext + grlPositionOffset, 1.0 );
Expand Down
Expand Up @@ -71,7 +71,9 @@ export class GreasedLineSimpleMaterial extends ShaderMaterial implements IGrease
{
attributes,
uniforms: [
"worldViewProjection",
"world",
"viewProjection",
"view",
"projection",
"grlColorsWidth",
"grlUseColors",
Expand Down
12 changes: 10 additions & 2 deletions packages/dev/core/src/Shaders/greasedLine.vertex.fx
@@ -1,10 +1,11 @@
precision highp float;
#include<instancesDeclaration>

attribute float grl_widths;
attribute vec3 grl_offsets;
attribute float grl_colorPointers;
attribute vec3 position;
uniform mat4 worldViewProjection;
uniform mat4 viewProjection;
uniform mat4 projection;
varying float grlCounters;
varying float grlColorPointer;
Expand All @@ -28,6 +29,8 @@ varying float grlColorPointer;
#endif

void main() {
#include<instancesVertex>

grlColorPointer = grl_colorPointers;

#ifdef GREASED_LINE_CAMERA_FACING
Expand All @@ -39,7 +42,12 @@ void main() {
vec3 grlNext = grl_nextAndCounters.xyz;
grlCounters = grl_nextAndCounters.w;

mat4 grlMatrix = worldViewProjection;
#ifdef INSTANCES
mat4 grlMatrix = viewProjection * finalWorld ;
#else
mat4 grlMatrix = viewProjection * world ;
#endif

vec3 grlPositionOffset = grl_offsets;
vec4 grlFinalPosition = grlMatrix * vec4( position + grlPositionOffset , 1.0 );
vec4 grlPrevPos = grlMatrix * vec4( grlPrevious + grlPositionOffset, 1.0 );
Expand Down