Densaugeo Posted July 19, 2016 Share Posted July 19, 2016 So I'm trying out Babylon by porting a demo I made in Three. I'm replicating the custom camera controls from old demo by writing to the camera._viewMatrix, which works fine for moving the camera around, but specular highlights are frozen. Since everything else seems to work, maybe the specular lighting uses a uniform that is not getting updated? Note: I would like to be able to control the camera with matrix transforms. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 19, 2016 Share Posted July 19, 2016 woot:) this is pretty rough We already have dozens of cameras (maybe the one you want is already here?) Regarding highlights, as you are hijacking the system, the cache engine is not aware of the updates and then it does not wipe any cache Quote Link to comment Share on other sites More sharing options...
Densaugeo Posted July 21, 2016 Author Share Posted July 21, 2016 After some investigation, I have found that the cameras are updating _viewMatrix based on position, rotation, etc.. Since _viewMatrix is the transform of the scene relative to the camera, I found it useful to define a new matrix (called 'transform'), which is the inverse of _viewMatrix. It is similar to _worldMatrix, but I avoided using the same name due to possible conflicts. Position.x, y, and z can be rebound to the appropriate fields on transform to keep them in sync with matrix updates. After that, _getViewMatrix can be altered to find _viewMatrix from the transform matrix instead of position, etc.. upVector and _cache.upVector can be hijacked to test transform for changes to know when to update _viewMatrix. this._viewMatrix = new BABYLON.Matrix(); this.transform = initialTransform; this.transform.invertToRef(this._viewMatrix); // ._viewMatrix now comes from .transform this._getViewMatrix = function() { this.transform.invertToRef(this._viewMatrix); return this._viewMatrix; } // Redirect .upVector + its cache to .transform, so that changes to .transform trigger updates this._cache.upVector = BABYLON.Matrix.Identity(); this.upVector = this.transform; // Bind .position to .transform Object.defineProperties(this.position, { x: { enumerable: true, get: () => this.transform.m[12], set: v => this.transform.m[12] = v }, y: ... }); Works as far as I can tell. Overall, not as bad as it could be. I'm still looking for a WebGL library that allows using matrices without such hacks though... GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.