Compare commits

..

2 Commits

Author SHA1 Message Date
trey 0e652c6cc0 save scene 2026-05-14 21:58:44 -05:00
trey 7259fe8d67 remove ortho, fix zoom, add dithering 2026-05-14 21:58:23 -05:00
5 changed files with 327 additions and 49 deletions
+13 -7
View File
@@ -1545,14 +1545,14 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4310657189086097289}
serializedVersion: 2
m_LocalRotation: {x: 0.30070576, y: -0, z: -0, w: 0.953717}
m_LocalPosition: {x: -0.35901004, y: 47.8, z: -70.2}
m_LocalRotation: {x: 0.1947668, y: 0.05645799, z: -0.01123019, w: 0.979159}
m_LocalPosition: {x: -2.5, y: 11.5, z: -21}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 6872729306491234319}
m_Father: {fileID: 5526037850913171920}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_LocalEulerAnglesHint: {x: 22.5, y: 6.6, z: 0}
--- !u!1 &4324082620616441630
GameObject:
m_ObjectHideFlags: 0
@@ -2188,7 +2188,7 @@ Camera:
near clip plane: 0.3
far clip plane: 1000
field of view: 60
orthographic: 1
orthographic: 0
orthographic size: 2.3
m_Depth: -1
m_CullingMask:
@@ -3159,11 +3159,17 @@ MonoBehaviour:
mouseSensitivity: 1000
minPitch: 10
maxPitch: 60
distance: 6
distance: 4
heightOffset: -0.5
followSpeed: 1000
maxZoom: 6
minZoom: 1
maxDistance: 6
minDistance: 1
zoomSpeed: 5
obstructionMask:
serializedVersion: 2
m_Bits: 4294967295
fadedAlpha: 0.25
fadeSpeed: 5
playerCamHome: {fileID: 2119885955527004040}
--- !u!114 &5412473048133157928
MonoBehaviour:
+141
View File
@@ -0,0 +1,141 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: OccludeTest
m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords:
- _ALPHAPREMULTIPLY_ON
- _SURFACE_TYPE_TRANSPARENT
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: 3000
stringTagMap:
RenderType: Transparent
disabledShaderPasses:
- MOTIONVECTORS
- DepthOnly
- SHADOWCASTER
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BaseMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SpecGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_Lightmaps:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_LightmapsInd:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_ShadowMasks:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _AddPrecomputedVelocity: 0
- _AlphaClip: 0
- _AlphaToMask: 0
- _Blend: 0
- _BlendModePreserveSpecular: 1
- _BumpScale: 1
- _ClearCoatMask: 0
- _ClearCoatSmoothness: 0
- _Cull: 2
- _Cutoff: 0.5
- _DetailAlbedoMapScale: 1
- _DetailNormalMapScale: 1
- _DstBlend: 10
- _DstBlendAlpha: 10
- _EnvironmentReflections: 1
- _GlossMapScale: 0
- _Glossiness: 0
- _GlossyReflections: 0
- _Metallic: 0
- _OcclusionStrength: 1
- _Parallax: 0.005
- _QueueOffset: 0
- _ReceiveShadows: 1
- _Smoothness: 0.5
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _SrcBlendAlpha: 1
- _Surface: 1
- _WorkflowMode: 1
- _XRMotionVectorsPass: 1
- _ZWrite: 0
m_Colors:
- _BaseColor: {r: 0.509434, g: 0.509434, b: 0.509434, a: 1}
- _Color: {r: 0.509434, g: 0.509434, b: 0.509434, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
m_BuildTextureStacks: []
m_AllowLocking: 1
--- !u!114 &3531991361068812674
MonoBehaviour:
m_ObjectHideFlags: 11
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
m_Name:
m_EditorClassIdentifier: Unity.RenderPipelines.Universal.Editor::UnityEditor.Rendering.Universal.AssetVersion
version: 10
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 78be8f8bd251f244ab82d30f189c8824
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:
+41 -34
View File
@@ -1822,11 +1822,6 @@ Transform:
m_Children: []
m_Father: {fileID: 265036979}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!20 &509486404 stripped
Camera:
m_CorrespondingSourceObject: {fileID: 7814557473141052265, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
m_PrefabInstance: {fileID: 7959480261809233915}
m_PrefabAsset: {fileID: 0}
--- !u!1 &562959765
GameObject:
m_ObjectHideFlags: 0
@@ -3695,7 +3690,7 @@ MeshRenderer:
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, type: 2}
- {fileID: 2100000, guid: 78be8f8bd251f244ab82d30f189c8824, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
@@ -4460,28 +4455,52 @@ PrefabInstance:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 2119885955527004040, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
propertyPath: m_LocalScale.y
value: 1
propertyPath: m_LocalPosition.x
value: -2.5
objectReference: {fileID: 0}
- target: {fileID: 2119885955527004040, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
propertyPath: m_LocalScale.z
value: 1
propertyPath: m_LocalPosition.y
value: 11.5
objectReference: {fileID: 0}
- target: {fileID: 2119885955527004040, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
propertyPath: m_LocalPosition.z
value: -21
objectReference: {fileID: 0}
- target: {fileID: 2119885955527004040, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
propertyPath: m_LocalRotation.w
value: 0.979159
objectReference: {fileID: 0}
- target: {fileID: 2119885955527004040, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
propertyPath: m_LocalRotation.x
value: 0.1947668
objectReference: {fileID: 0}
- target: {fileID: 2119885955527004040, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
propertyPath: m_LocalRotation.y
value: 0.05645799
objectReference: {fileID: 0}
- target: {fileID: 2119885955527004040, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
propertyPath: m_LocalRotation.z
value: -0.01123019
objectReference: {fileID: 0}
- target: {fileID: 2119885955527004040, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 22.5
objectReference: {fileID: 0}
- target: {fileID: 2119885955527004040, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 6.6
objectReference: {fileID: 0}
- target: {fileID: 5478143440182735446, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
propertyPath: minPitch
value: 10
propertyPath: distance
value: 4
objectReference: {fileID: 0}
- target: {fileID: 5478143440182735446, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
propertyPath: MainCamera
value:
objectReference: {fileID: 509486404}
- target: {fileID: 5478143440182735446, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
propertyPath: followSpeed
value: 1000
propertyPath: zoomSpeed
value: 5
objectReference: {fileID: 0}
- target: {fileID: 5478143440182735446, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
propertyPath: mouseSensitivity
value: 1000
propertyPath: obstructionMask.m_Bits
value: 4294967295
objectReference: {fileID: 0}
- target: {fileID: 5526037850913171920, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
propertyPath: m_LocalPosition.x
@@ -4523,20 +4542,8 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6872729306491234319, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6872729306491234319, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6872729306491234319, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6872729306491234319, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
- target: {fileID: 7814557473141052265, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
propertyPath: orthographic
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9054701043111961555, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
+124 -8
View File
@@ -2,6 +2,7 @@
using System.Linq;
using Unity.VisualScripting;
using UnityEngine;
using static Unity.Cinemachine.CinemachineTargetGroup;
using static UnityEngine.GraphicsBuffer;
public class CameraController : MonoBehaviour
@@ -16,20 +17,36 @@ public class CameraController : MonoBehaviour
public float mouseSensitivity = 200f;
public float minPitch = -30f;
public float maxPitch = 60f;
public float distance = 6f;
public float distance = 5f;
public float heightOffset = -0.5f;
public float followSpeed = 10f;
public float maxZoom = 6f;
public float minZoom = 1f;
private float zoom = 2.3f;
public float maxDistance = 6f;
public float minDistance = 1f;
public float zoomSpeed = 5f;
private float yaw;
private float pitch;
private float currentDistance;
private float distanceVelocity;
[Header("Occlusion Settings")]
public LayerMask obstructionMask;
public float fadedAlpha = 0.25f;
public float fadeSpeed = 5f;
private Dictionary<Renderer, float> currentAlpha =
new Dictionary<Renderer, float>();
private Dictionary<Renderer, float> targetAlpha =
new Dictionary<Renderer, float>();
public Transform playerCamHome;
Transform dougBody;
private void Update()
{
UpdateOcclusion();
UpdateFade();
if (Input.GetMouseButton(1))
{
HandleFreeCamRotation();
@@ -42,6 +59,7 @@ void Start()
yaw = angles.y;
pitch = angles.x;
currentDistance = distance;
}
/// <summary>
@@ -102,6 +120,9 @@ void HandleFreeCamRotation()
{
if (dougBody == null)
{
if (GameManager.Instance.PlayerController.DougBody == null)
return;
dougBody = GameManager.Instance.PlayerController.DougBody.transform;
}
@@ -119,15 +140,23 @@ void HandleFreeCamRotation()
// Zoom
float scroll = Input.GetAxis("Mouse ScrollWheel");
zoom -= scroll * 2f;
zoom = Mathf.Clamp(zoom, minZoom, maxZoom);
MainCamera.orthographicSize = zoom;
if (Mathf.Abs(scroll) > 0.0001f)
{
distance -= scroll * zoomSpeed;
distance = Mathf.Clamp(distance, minDistance, maxDistance);
}
currentDistance = Mathf.SmoothDamp(
currentDistance,
distance,
ref distanceVelocity,
0.05f);
// Rotation
Quaternion rotation = Quaternion.Euler(pitch, yaw, 0);
// Desired Position
Vector3 offset = rotation * Vector3.forward * -distance;
Vector3 offset = rotation * Vector3.forward * -currentDistance;
Vector3 desiredPosition = target + offset;
// Smooth Follow
@@ -140,6 +169,93 @@ void HandleFreeCamRotation()
// Look at player
playerCamHome.transform.LookAt(target + Vector3.up);
}
void UpdateOcclusion()
{
if (dougBody == null)
{
if (GameManager.Instance.PlayerController.DougBody == null)
return;
dougBody = GameManager.Instance.PlayerController.DougBody.transform;
}
if (dougBody == null) return;
// Reset all renderers to visible
foreach (Renderer r in new List<Renderer>(targetAlpha.Keys))
{
targetAlpha[r] = 1f;
}
Vector3 dir =
MainCamera.transform.position - dougBody.position;
float dist = dir.magnitude;
RaycastHit[] hits = Physics.RaycastAll(
dougBody.position,
dir.normalized,
dist,
obstructionMask,
QueryTriggerInteraction.Ignore);
foreach (RaycastHit hit in hits)
{
Renderer r = hit.collider.GetComponent<Renderer>();
if (r == null)
continue;
if (!currentAlpha.ContainsKey(r))
{
currentAlpha[r] = 1f;
targetAlpha[r] = 1f;
}
targetAlpha[r] = fadedAlpha;
}
}
void UpdateFade()
{
List<Renderer> renderers =
new List<Renderer>(currentAlpha.Keys);
foreach (Renderer r in renderers)
{
float current = currentAlpha[r];
float target = targetAlpha[r];
current = Mathf.Lerp(
current,
target,
Time.deltaTime * fadeSpeed);
currentAlpha[r] = current;
foreach (Material mat in r.materials)
{
Color c = mat.color;
c.a = current;
if (Mathf.Abs(current - targetAlpha[r]) < 0.05f)
{
c.a = targetAlpha[r];
}
mat.color = c;
}
// Cleanup once fully restored
if (Mathf.Abs(current - 1f) < 0.01f &&
Mathf.Abs(target - 1f) < 0.01f)
{
currentAlpha.Remove(r);
targetAlpha.Remove(r);
}
}
}
}
public enum CameraControlMode