protected virtual void CameraPreRender(Camera camera) { if (material != null) { var velocity = StretchVector; var observer = default(SgtCamera); if (SgtCamera.TryFind(camera, ref observer) == true) { material.SetFloat("_CameraRollAngle", observer.RollAngle * Mathf.Deg2Rad); velocity += observer.Velocity * StretchScale; } else { material.SetFloat("_CameraRollAngle", 0.0f); } if (Stretch == true) { material.SetVector("_StretchVector", velocity); material.SetVector("_StretchDirection", velocity.normalized); material.SetFloat("_StretchLength", velocity.magnitude); } else { material.SetVector("_StretchVector", Vector3.zero); material.SetVector("_StretchDirection", Vector3.zero); material.SetFloat("_StretchLength", 0.0f); } } }
protected void CameraPreRender(Camera camera) { if (material != null) { var observer = default(SgtCamera); if (SgtCamera.TryFind(camera, ref observer) == true) { material.SetFloat("_CameraRollAngle", observer.RollAngle * Mathf.Deg2Rad); } else { material.SetFloat("_CameraRollAngle", 0.0f); } // Write these once to save CPU if (renderedThisFrame == false && material != null) { renderedThisFrame = true; // Write lights and shadows SgtHelper.SetTempMaterial(material); SgtLight.Write(Lit, transform.position, transform, null, 1.0f, 2); SgtShadow.Write(Lit, gameObject, 2); } } }
protected override void HandleCameraDraw(Camera camera) { if (SgtHelper.CanDraw(gameObject, camera) == false) { return; } var properties = shaderProperties.GetProperties(material, camera); var velocity = stretchVector; var sgtCamera = default(SgtCamera); if (SgtCamera.TryFind(camera, ref sgtCamera) == true) { properties.SetFloat(SgtShader._CameraRollAngle, sgtCamera.RollAngle * Mathf.Deg2Rad); var cameraVelocity = sgtCamera.Velocity; var cameraSpeed = cameraVelocity.magnitude; if (cameraSpeed > stretchLimit) { cameraVelocity = cameraVelocity.normalized * stretchLimit; } velocity += cameraVelocity * stretchScale; } else { properties.SetFloat(SgtShader._CameraRollAngle, 0.0f); } if (stretch == true) { properties.SetVector(SgtShader._StretchVector, velocity); properties.SetVector(SgtShader._StretchDirection, velocity.normalized); properties.SetFloat(SgtShader._StretchLength, velocity.magnitude); } else { properties.SetVector(SgtShader._StretchVector, Vector3.zero); properties.SetVector(SgtShader._StretchDirection, Vector3.zero); properties.SetFloat(SgtShader._StretchLength, 0.0f); } if (camera.orthographic == true) { properties.SetFloat(SgtShader._ClampSizeScale, camera.orthographicSize * 0.0025f); } else { properties.SetFloat(SgtShader._ClampSizeScale, Mathf.Tan(camera.fieldOfView * Mathf.Deg2Rad * 0.5f) * 2.0f); } HandleDrawMesh(camera, properties); }
protected virtual void CameraPreRender(Camera camera) { if (material != null) { var velocity = StretchVector; var sgtCamera = default(SgtCamera); if (SgtCamera.TryFind(camera, ref sgtCamera) == true) { material.SetFloat(SgtShader._CameraRollAngle, sgtCamera.RollAngle * Mathf.Deg2Rad); var cameraVelocity = sgtCamera.Velocity; var cameraSpeed = cameraVelocity.magnitude; if (cameraSpeed > StretchLimit) { cameraVelocity = cameraVelocity.normalized * StretchLimit; } velocity += cameraVelocity * StretchScale; } else { material.SetFloat(SgtShader._CameraRollAngle, 0.0f); } if (Stretch == true) { material.SetVector(SgtShader._StretchVector, velocity); material.SetVector(SgtShader._StretchDirection, velocity.normalized); material.SetFloat(SgtShader._StretchLength, velocity.magnitude); } else { material.SetVector(SgtShader._StretchVector, Vector3.zero); material.SetVector(SgtShader._StretchDirection, Vector3.zero); material.SetFloat(SgtShader._StretchLength, 0.0f); } if (camera.orthographic == true) { material.SetFloat(SgtShader._ClampSizeScale, camera.orthographicSize * 0.0025f); } else { material.SetFloat(SgtShader._ClampSizeScale, Mathf.Tan(camera.fieldOfView * Mathf.Deg2Rad * 0.5f) * 2.0f); } } }
private void PreCull(Camera camera) { if (this == FirstInstance) { var cameraRotation = camera.transform.rotation; var rollRotation = cameraRotation; var observer = default(SgtCamera); if (SgtCamera.TryFind(camera, ref observer) == true) { rollRotation *= observer.RollQuaternion; } var billboard = SgtFastBillboard.FirstInstance; var mask = camera.cullingMask; var position = camera.transform.position; for (var i = 0; i < SgtFastBillboard.InstanceCount; i++) { if ((billboard.Mask & mask) != 0) { var rotation = default(Quaternion); if (billboard.RollWithCamera == true) { rotation = rollRotation * billboard.Rotation; } else { rotation = cameraRotation * billboard.Rotation; } if (billboard.AvoidClipping == true) { var directionA = Vector3.Normalize(billboard.transform.position - position); var directionB = rotation * Vector3.forward; var theta = Vector3.Angle(directionA, directionB); var axis = Vector3.Cross(directionA, directionB); rotation = Quaternion.AngleAxis(theta, -axis) * rotation; } billboard.cachedTransform.rotation = rotation; } billboard = billboard.NextInstance; } } }
protected override void HandleCameraDraw(Camera camera) { if (SgtHelper.CanDraw(gameObject, camera) == false) { return; } var properties = shaderProperties.GetProperties(material, camera); var sgtCamera = default(SgtCamera); if (SgtCamera.TryFind(camera, ref sgtCamera) == true) { properties.SetFloat(SgtShader._CameraRollAngle, sgtCamera.RollAngle * Mathf.Deg2Rad); } else { properties.SetFloat(SgtShader._CameraRollAngle, 0.0f); } Graphics.DrawMesh(mesh, transform.localToWorldMatrix, material, gameObject.layer, camera, 0, properties); }
private void CameraPreCull(Camera camera) { Revert(); { var cameraRotation = camera.transform.rotation; var rollRotation = cameraRotation; var observer = default(SgtCamera); var rotation = default(Quaternion); if (SgtCamera.TryFind(camera, ref observer) == true) { rollRotation *= observer.RollQuaternion; } if (RollWithCamera == true) { rotation = rollRotation; } else { rotation = cameraRotation; } if (AvoidClipping == true) { var directionA = Vector3.Normalize(transform.position - camera.transform.position); var directionB = rotation * Vector3.forward; var theta = Vector3.Angle(directionA, directionB); var axis = Vector3.Cross(directionA, directionB); rotation = Quaternion.AngleAxis(theta, -axis) * rotation; } cachedTransform.rotation = rotation; } Save(camera); }