@@ -460,28 +460,64 @@ VROConcurrentBuffer &VROMaterialSubstrateMetal::bindMaterialUniforms(float opaci
460460 return *_materialUniformsBuffer;
461461}
462462
463- void VROMaterialSubstrateMetal::updateSortKey (VROSortKey &key) const {
463+ void VROMaterialSubstrateMetal::updateSortKey (VROSortKey &key, const std::vector<std::shared_ptr<VROLight>> &lights,
464+ const VRORenderContext &context,
465+ std::shared_ptr<VRODriver> driver) {
464466 key.shader = _program->getShaderId ();
465467 key.textures = hashTextures (_textures);
466468}
467469
470+ bool VROMaterialSubstrateMetal::bindShader (int lightsHash,
471+ const std::vector<std::shared_ptr<VROLight>> &lights,
472+ const VRORenderContext &context,
473+ std::shared_ptr<VRODriver> &driver) {
474+ // In Metal, pipeline state is bound by the geometry substrate, not the material substrate.
475+ // However, we need to bind the lighting uniforms here, similar to OpenGL.
476+ // This is the CRITICAL FIX: bindLights was defined but never called!
477+ NSLog (@" [METAL LIGHTING] bindShader() called with %zu lights, hash=%d" , lights.size(), lightsHash);
478+ bindLights (lightsHash, lights, context, driver);
479+ NSLog (@" [METAL LIGHTING] bindLights() completed" );
480+ return true ;
481+ }
482+
483+ void VROMaterialSubstrateMetal::bindProperties (std::shared_ptr<VRODriver> &driver) {
484+ // In Metal, material properties are bound via bindMaterialUniforms in the geometry substrate
485+ // This is called from VROGeometrySubstrateMetal::renderMaterial
486+ }
487+
488+ void VROMaterialSubstrateMetal::bindGeometry (float opacity, const VROGeometry &geometry) {
489+ // In Metal, geometry-specific properties are handled in the geometry substrate
490+ }
491+
492+ void VROMaterialSubstrateMetal::bindView (VROMatrix4f modelMatrix, VROMatrix4f viewMatrix,
493+ VROMatrix4f projectionMatrix, VROMatrix4f normalMatrix,
494+ VROVector3f cameraPosition, VROEyeType eyeType,
495+ const VRORenderContext &context) {
496+ // In Metal, view uniforms are bound in VROGeometrySubstrateMetal::render
497+ }
498+
499+ void VROMaterialSubstrateMetal::updateTextures () {
500+ // Textures are managed through the _textures vector and updated when materials change
501+ }
502+
468503void VROMaterialSubstrateMetal::bindShader () {
469- // Do nothing in Metal, consider changing this to binding pipeline state?
470- // The problem is that pipeline state in metal emcompasses both shader and
471- // vertex layout
504+ // Legacy method kept for compatibility
505+ // The virtual bindShader(int lightsHash, ...) should be used instead
472506}
473507
474508void VROMaterialSubstrateMetal::bindLights (int lightsHash,
475509 const std::vector<std::shared_ptr<VROLight>> &lights,
476510 const VRORenderContext &context,
477511 std::shared_ptr<VRODriver> &driver) {
478-
512+
513+ NSLog (@" [METAL LIGHTING] bindLights() starting - received %zu lights" , lights.size());
514+
479515 VRODriverMetal &metal = (VRODriverMetal &)(*driver.get ());
480516 id <MTLRenderCommandEncoder> renderEncoder = metal.getRenderTarget ()->getRenderEncoder ();
481-
517+
482518 VROEyeType eyeType = context.getEyeType ();
483519 int frame = context.getFrame ();
484-
520+
485521 VROSceneLightingUniforms *uniforms = (VROSceneLightingUniforms *)_lightingUniformsBuffer->getWritableContents (eyeType,
486522 frame);
487523 uniforms->num_lights = 0 ;
@@ -508,13 +544,21 @@ void VROMaterialSubstrateMetal::bindLights(int lightsHash,
508544 }
509545
510546 uniforms->ambient_light_color = toVectorFloat3 (ambientLight);
511-
547+
548+ NSLog (@" [METAL LIGHTING] Final values - num_lights=%d, ambient=(%f,%f,%f)" ,
549+ uniforms->num_lights,
550+ uniforms->ambient_light_color.x,
551+ uniforms->ambient_light_color.y,
552+ uniforms->ambient_light_color.z);
553+
512554 [renderEncoder setVertexBuffer:_lightingUniformsBuffer->getMTLBuffer (eyeType)
513555 offset:_lightingUniformsBuffer->getWriteOffset (frame)
514556 atIndex:4 ];
515557 [renderEncoder setFragmentBuffer:_lightingUniformsBuffer->getMTLBuffer (eyeType)
516558 offset:_lightingUniformsBuffer->getWriteOffset (frame)
517559 atIndex:4 ];
560+
561+ NSLog (@" [METAL LIGHTING] Lighting buffer bound at index 4 for vertex and fragment shaders" );
518562}
519563
520564uint32_t VROMaterialSubstrateMetal::hashTextures (const std::vector<std::shared_ptr<VROTexture>> &textures) const {
0 commit comments