Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/dev/core/src/Rendering/objectRenderer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// eslint-disable-next-line import/no-internal-modules
import type { SmartArray, Nullable, Immutable, Camera, Scene, AbstractMesh, SubMesh, Material, IParticleSystem } from "core/index";
import type { SmartArray, Nullable, Immutable, Camera, Scene, AbstractMesh, SubMesh, Material, IParticleSystem, InstancedMesh } from "core/index";
import { Observable } from "../Misc/observable";
import { RenderingManager } from "../Rendering/renderingManager";
import { Constants } from "../Engines/constants";
Expand Down Expand Up @@ -252,7 +252,11 @@ export class ObjectRenderer {
}
for (let j = 0; j < meshes.length; ++j) {
for (let i = 0; i < this.options.numPasses; ++i) {
meshes[j].setMaterialForRenderPass(this._renderPassIds[i], material !== undefined ? (Array.isArray(material) ? material[i] : material) : undefined);
let mesh = meshes[j];
if (meshes[j].isAnInstance) {
mesh = (meshes[j] as InstancedMesh).sourceMesh;
}
mesh.setMaterialForRenderPass(this._renderPassIds[i], material !== undefined ? (Array.isArray(material) ? material[i] : material) : undefined);
}
}
}
Expand Down
23 changes: 20 additions & 3 deletions packages/dev/core/src/Shaders/iblVoxelGrid.vertex.fx
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
attribute vec3 position;
attribute vec3 normal;

varying vec3 vNormalizedPosition;

uniform mat4 world;
#include<bonesDeclaration>
#include<bakedVertexAnimationDeclaration>
#include<instancesDeclaration>

#include<morphTargetsVertexGlobalDeclaration>
#include<morphTargetsVertexDeclaration>[0..maxSimultaneousMorphTargets]

uniform mat4 invWorldScale;
uniform mat4 viewMatrix;

void main(void) {
vec3 positionUpdated = position;

#include<morphTargetsVertexGlobal>
#include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]

#include<instancesVertex>

#include<bonesVertex>
#include<bakedVertexAnimation>

vec4 worldPos = finalWorld * vec4(positionUpdated, 1.0);

// inverse scale this by world scale to put in 0-1 space.
gl_Position = viewMatrix * invWorldScale * world * vec4(position, 1.);
gl_Position = viewMatrix * invWorldScale * worldPos;
// gl_Position.xyz = gl_Position.zyx;
vNormalizedPosition.xyz = gl_Position.xyz * 0.5 + 0.5;
// vNormalizedPosition.xyz = vNormalizedPosition.zyx;
Expand Down
25 changes: 21 additions & 4 deletions packages/dev/core/src/ShadersWGSL/iblVoxelGrid.vertex.fx
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
attribute position: vec3f;
attribute normal: vec3f;

varying vNormalizedPosition: vec3f;

uniform world: mat4x4f;
#include<bonesDeclaration>
#include<bakedVertexAnimationDeclaration>
#include<instancesDeclaration>

#include<morphTargetsVertexGlobalDeclaration>
#include<morphTargetsVertexDeclaration>[0..maxSimultaneousMorphTargets]

uniform invWorldScale: mat4x4f;
uniform viewMatrix: mat4x4f;

@vertex
fn main(input : VertexInputs) -> FragmentInputs {
var positionUpdated = vertexInputs.position;

#include<morphTargetsVertexGlobal>
#include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]

#include<instancesVertex>

#include<bonesVertex>
#include<bakedVertexAnimation>

let worldPos = finalWorld * vec4f(positionUpdated, 1.0);

// inverse scale this by world scale to put in 0-1 space.
vertexOutputs.position = uniforms.viewMatrix * uniforms.invWorldScale * uniforms.world * vec4f(input.position, 1.);
vertexOutputs.position = uniforms.viewMatrix * uniforms.invWorldScale * worldPos;
// vertexOutputs.position.xyz = vertexOutputs.position.zyx;
vertexOutputs.vNormalizedPosition = vertexOutputs.position.xyz * 0.5 + 0.5;
// vNormalizedPosition.xyz = vNormalizedPosition.zyx;

#ifdef IS_NDC_HALF_ZRANGE
vertexOutputs.position = vec4f(vertexOutputs.position.x, vertexOutputs.position.y, vertexOutputs.position.z * 0.5 + 0.5, vertexOutputs.position.w);
#endif
}
}