Bladeren bron

adding in shadow bias fixes into camera lighting shadow fix

Justin Gilman 1 jaar geleden
bovenliggende
commit
471ff1d6fd

+ 0 - 36
Assets/Components/DirectionalLightFixForMobileCamera.re.ts

@@ -1,36 +0,0 @@
-import * as RE from 'rogue-engine';
-import * as THREE from 'three'
-
-export default class DirectionalLightFixForMobileCamera extends RE.Component {
-  initialOffset: THREE.Vector3 = new THREE.Vector3()
-  currentOffset: THREE.Vector3 = new THREE.Vector3()
-  awake() {
-
-  }
-
-  start() {
-    const activeCamera = RE.App.currentScene.getObjectByProperty("uuid", RE.App.activeCamera) as THREE.Object3D
-    const directionalLight: THREE.DirectionalLight = this.object3d as THREE.DirectionalLight
-
-    this.initialOffset.copy(this.object3d.position)
-    this.initialOffset.sub(new THREE.Vector3(0, 0, 0))
-    this.updatePositions()
-    directionalLight.target = activeCamera
-  }
-
-  update() {
-    this.updatePositions()
-  }
-
-  updatePositions() {
-    const activeCamera = RE.App.currentScene.getObjectByProperty("uuid", RE.App.activeCamera) as THREE.Object3D
-    const directionalLight: THREE.DirectionalLight = this.object3d as THREE.DirectionalLight
-    
-    this.currentOffset.copy(this.initialOffset).add(activeCamera.position)
-    directionalLight.position.set(this.currentOffset.x, this.currentOffset.y, this.currentOffset.z)
-    directionalLight.shadow.camera.position.set(this.currentOffset.x, this.currentOffset.y, this.currentOffset.z)
-  }
-}
-
-RE.registerComponent(DirectionalLightFixForMobileCamera);
-        

+ 57 - 0
Assets/Components/DirectionalLightShadowFixForMobileCamera.re.ts

@@ -0,0 +1,57 @@
+import * as RE from 'rogue-engine';
+import * as THREE from 'three'
+
+export default class DirectionalLightShadowFixForMobileCamera extends RE.Component {
+  initialOffset: THREE.Vector3 = new THREE.Vector3()
+  currentOffset: THREE.Vector3 = new THREE.Vector3()
+
+  private _normalBias = 0.04;
+
+  get light() {
+    return this.object3d as THREE.DirectionalLight
+  }
+
+  get camera() {
+    return RE.App.currentScene.getObjectByProperty("uuid", RE.App.activeCamera) as THREE.Camera
+  }
+
+  get shadow() {
+    return this.light.shadow;
+  }
+
+  @RE.props.num()
+  get normalBias() {
+    return this._normalBias;
+  }
+
+  set normalBias(value: number) {
+    this._normalBias = value;
+    if (this.shadow) { this.shadow.normalBias = value; }
+  }
+
+  awake() {
+
+  }
+
+  start() {
+    this.initialOffset.copy(this.light.position)
+    this.initialOffset.sub(new THREE.Vector3(0, 0, 0))
+    this.updatePositions()
+    this.light.target = this.camera
+  }
+
+  update() {
+    this.updatePositions()
+  }
+
+  updatePositions() {    
+    this.currentOffset.copy(this.initialOffset).add(this.camera.position)
+    this.light.position.set(this.currentOffset.x, this.currentOffset.y, this.currentOffset.z)
+    if(this.shadow) {
+      this.shadow.camera.position.set(this.currentOffset.x, this.currentOffset.y, this.currentOffset.z)
+    }
+  }
+}
+
+RE.registerComponent(DirectionalLightShadowFixForMobileCamera);
+        

File diff suppressed because it is too large
+ 0 - 0
Assets/MainScene.rogueScene


File diff suppressed because it is too large
+ 0 - 0
dist/rogue-editor-user-scripts.js


+ 48 - 18
dist/rogue-engine-user-scripts.js

@@ -469,53 +469,83 @@ rogue_engine__WEBPACK_IMPORTED_MODULE_0__.registerComponent(BallRaycastReceiver)
 
 /***/ }),
 
-/***/ "./Assets/Components/DirectionalLightFixForMobileCamera.re.ts":
-/*!********************************************************************!*\
-  !*** ./Assets/Components/DirectionalLightFixForMobileCamera.re.ts ***!
-  \********************************************************************/
+/***/ "./Assets/Components/DirectionalLightShadowFixForMobileCamera.re.ts":
+/*!**************************************************************************!*\
+  !*** ./Assets/Components/DirectionalLightShadowFixForMobileCamera.re.ts ***!
+  \**************************************************************************/
 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
 
 __webpack_require__.r(__webpack_exports__);
 /* harmony export */ __webpack_require__.d(__webpack_exports__, {
-/* harmony export */   "default": () => (/* binding */ DirectionalLightFixForMobileCamera)
+/* harmony export */   "default": () => (/* binding */ DirectionalLightShadowFixForMobileCamera)
 /* harmony export */ });
 /* harmony import */ var rogue_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! rogue-engine */ "rogue-engine");
 /* harmony import */ var rogue_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(rogue_engine__WEBPACK_IMPORTED_MODULE_0__);
 /* harmony import */ var three__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! three */ "three");
 /* harmony import */ var three__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(three__WEBPACK_IMPORTED_MODULE_1__);
 var __defProp = Object.defineProperty;
+var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
 var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
+var __decorateClass = (decorators, target, key, kind) => {
+  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
+  for (var i = decorators.length - 1, decorator; i >= 0; i--)
+    if (decorator = decorators[i])
+      result = (kind ? decorator(target, key, result) : decorator(result)) || result;
+  if (kind && result)
+    __defProp(target, key, result);
+  return result;
+};
 
 
-class DirectionalLightFixForMobileCamera extends rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Component {
+class DirectionalLightShadowFixForMobileCamera extends rogue_engine__WEBPACK_IMPORTED_MODULE_0__.Component {
   constructor() {
     super(...arguments);
     this.initialOffset = new three__WEBPACK_IMPORTED_MODULE_1__.Vector3();
     this.currentOffset = new three__WEBPACK_IMPORTED_MODULE_1__.Vector3();
+    this._normalBias = 0.04;
+  }
+  get light() {
+    return this.object3d;
+  }
+  get camera() {
+    return rogue_engine__WEBPACK_IMPORTED_MODULE_0__.App.currentScene.getObjectByProperty("uuid", rogue_engine__WEBPACK_IMPORTED_MODULE_0__.App.activeCamera);
+  }
+  get shadow() {
+    return this.light.shadow;
+  }
+  get normalBias() {
+    return this._normalBias;
+  }
+  set normalBias(value) {
+    this._normalBias = value;
+    if (this.shadow) {
+      this.shadow.normalBias = value;
+    }
   }
   awake() {
   }
   start() {
-    const activeCamera = rogue_engine__WEBPACK_IMPORTED_MODULE_0__.App.currentScene.getObjectByProperty("uuid", rogue_engine__WEBPACK_IMPORTED_MODULE_0__.App.activeCamera);
-    const directionalLight = this.object3d;
-    this.initialOffset.copy(this.object3d.position);
+    this.initialOffset.copy(this.light.position);
     this.initialOffset.sub(new three__WEBPACK_IMPORTED_MODULE_1__.Vector3(0, 0, 0));
     this.updatePositions();
-    directionalLight.target = activeCamera;
+    this.light.target = this.camera;
   }
   update() {
     this.updatePositions();
   }
   updatePositions() {
-    const activeCamera = rogue_engine__WEBPACK_IMPORTED_MODULE_0__.App.currentScene.getObjectByProperty("uuid", rogue_engine__WEBPACK_IMPORTED_MODULE_0__.App.activeCamera);
-    const directionalLight = this.object3d;
-    this.currentOffset.copy(this.initialOffset).add(activeCamera.position);
-    directionalLight.position.set(this.currentOffset.x, this.currentOffset.y, this.currentOffset.z);
-    directionalLight.shadow.camera.position.set(this.currentOffset.x, this.currentOffset.y, this.currentOffset.z);
+    this.currentOffset.copy(this.initialOffset).add(this.camera.position);
+    this.light.position.set(this.currentOffset.x, this.currentOffset.y, this.currentOffset.z);
+    if (this.shadow) {
+      this.shadow.camera.position.set(this.currentOffset.x, this.currentOffset.y, this.currentOffset.z);
+    }
   }
 }
-__name(DirectionalLightFixForMobileCamera, "DirectionalLightFixForMobileCamera");
-rogue_engine__WEBPACK_IMPORTED_MODULE_0__.registerComponent(DirectionalLightFixForMobileCamera);
+__name(DirectionalLightShadowFixForMobileCamera, "DirectionalLightShadowFixForMobileCamera");
+__decorateClass([
+  rogue_engine__WEBPACK_IMPORTED_MODULE_0__.props.num()
+], DirectionalLightShadowFixForMobileCamera.prototype, "normalBias", 1);
+rogue_engine__WEBPACK_IMPORTED_MODULE_0__.registerComponent(DirectionalLightShadowFixForMobileCamera);
 
 
 /***/ }),
@@ -5683,7 +5713,7 @@ const OutputShader = {
 /******/ 	// Load entry module and return exports
 /******/ 	__webpack_require__("./Assets/Components/Animator.re.ts");
 /******/ 	__webpack_require__("./Assets/Components/BallRaycastReceiver.re.ts");
-/******/ 	__webpack_require__("./Assets/Components/DirectionalLightFixForMobileCamera.re.ts");
+/******/ 	__webpack_require__("./Assets/Components/DirectionalLightShadowFixForMobileCamera.re.ts");
 /******/ 	__webpack_require__("./Assets/Components/DummyShooter.re.ts");
 /******/ 	__webpack_require__("./Assets/Components/FaceDirectionOfVelocityComponent.re.ts");
 /******/ 	__webpack_require__("./Assets/Components/FloorCheckComponent.re.ts");

File diff suppressed because it is too large
+ 0 - 0
dist/rogue-engine-user-scripts.js.map


+ 1 - 1
rogue-config.json

@@ -1 +1 @@
-{"title":"ShipShoot","scenes":[{"name":"Menu","uuid":"56445644-18ed-4c5b-8f26-b918e047fbb3"},{"name":"MainScene","uuid":"1aaeccac-8dcd-42b5-9eaf-69b66b6b54b6"}],"projectVersion":22,"lastOpenedScene":"\\Assets\\Menu.rogueScene"}
+{"title":"ShipShoot","scenes":[{"name":"Menu","uuid":"56445644-18ed-4c5b-8f26-b918e047fbb3"},{"name":"MainScene","uuid":"1aaeccac-8dcd-42b5-9eaf-69b66b6b54b6"}],"projectVersion":22,"lastOpenedScene":"\\Assets\\MainScene.rogueScene"}

Some files were not shown because too many files changed in this diff