This commit is contained in:
2025-05-16 23:31:59 +08:00
parent 9e4fef3f1e
commit d891e3f0ee
1198 changed files with 274242 additions and 1558 deletions

View File

@@ -0,0 +1,30 @@
using UnityEngine;
namespace VLB_Samples
{
[RequireComponent(typeof(Camera))]
public class CameraToggleBeamVisibility : MonoBehaviour
{
[SerializeField] KeyCode m_KeyCode = KeyCode.Space;
void Update()
{
if (Input.GetKeyDown(m_KeyCode))
{
var cam = GetComponent<Camera>();
int layerID = VLB.Config.Instance.geometryLayerID;
int layerMask = 1 << layerID;
if ((cam.cullingMask & layerMask) == layerMask)
{
cam.cullingMask &= ~layerMask;
}
else
{
cam.cullingMask |= layerMask;
}
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: c266971950f6c8249832946861d54fa8
timeCreated: 1507707781
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,53 @@
using UnityEngine;
namespace VLB_Samples
{
[RequireComponent(typeof(Collider), typeof(Rigidbody), typeof(MeshRenderer))]
public class CheckIfInsideBeam : MonoBehaviour
{
bool isInsideBeam = false;
Material m_Material = null;
Collider m_Collider = null;
void Start()
{
m_Collider = GetComponent<Collider>();
Debug.Assert(m_Collider);
var meshRenderer = GetComponent<MeshRenderer>();
if (meshRenderer)
m_Material = meshRenderer.material;
Debug.Assert(m_Material);
}
void Update()
{
if (m_Material)
{
m_Material.SetColor("_Color", isInsideBeam ? Color.green : Color.red);
}
}
void FixedUpdate()
{
isInsideBeam = false;
}
void OnTriggerStay(Collider trigger)
{
var dynamicOcclusion = trigger.GetComponent<VLB.DynamicOcclusionRaycasting>();
if (dynamicOcclusion)
{
// This GameObject is inside the beam's TriggerZone.
// Make sure it's not hidden by an occluder
isInsideBeam = !dynamicOcclusion.IsColliderHiddenByDynamicOccluder(m_Collider);
}
else
{
isInsideBeam = true;
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: aa80be3114439164cb57d970b56bc816
timeCreated: 1531568745
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,13 @@
using UnityEngine;
namespace VLB_Samples
{
public class FeaturesNotSupportedMessage : MonoBehaviour
{
void Start()
{
if(!VLB.Noise3D.isSupported)
Debug.LogWarning(VLB.Noise3D.isNotSupportedString);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: dd7339057fb22c84ea73609eb1efb890
timeCreated: 1514884227
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,72 @@
using UnityEngine;
namespace VLB_Samples
{
public class FreeCameraController : MonoBehaviour
{
public float cameraSensitivity = 90;
public float speedNormal = 10;
public float speedFactorSlow = 0.25f;
public float speedFactorFast = 3;
public float speedClimb = 4;
float rotationH = 0.0f;
float rotationV = 0.0f;
bool m_UseMouseView = true;
bool useMouseView
{
get { return m_UseMouseView; }
set
{
m_UseMouseView = value;
Cursor.lockState = value ? CursorLockMode.Locked : CursorLockMode.None;
Cursor.visible = !value;
}
}
void Start()
{
useMouseView = true;
var euler = transform.rotation.eulerAngles;
rotationH = euler.y;
rotationV = euler.x;
if (rotationV > 180f)
rotationV -= 360f;
}
void Update()
{
if (useMouseView)
{
rotationH += Input.GetAxis("Mouse X") * cameraSensitivity * Time.deltaTime;
rotationV -= Input.GetAxis("Mouse Y") * cameraSensitivity * Time.deltaTime;
}
rotationV = Mathf.Clamp(rotationV, -90, 90);
transform.rotation = Quaternion.AngleAxis(rotationH, Vector3.up);
transform.rotation *= Quaternion.AngleAxis(rotationV, Vector3.right);
var speed = speedNormal;
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) speed *= speedFactorFast;
else if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) speed *= speedFactorSlow;
transform.position += speed * Input.GetAxis("Vertical") * Time.deltaTime * transform.forward;
transform.position += speed * Input.GetAxis("Horizontal") * Time.deltaTime * transform.right;
if (Input.GetKey(KeyCode.Q)) { transform.position += speedClimb * Time.deltaTime * Vector3.up; }
if (Input.GetKey(KeyCode.E)) { transform.position += speedClimb * Time.deltaTime * Vector3.down; }
if (
#if !UNITY_EDITOR
Input.GetMouseButtonDown(0) ||
#endif
Input.GetMouseButtonDown(1) || Input.GetMouseButtonDown(2))
useMouseView = !useMouseView;
if (Input.GetKeyDown(KeyCode.Escape))
useMouseView = false;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 73cef9fd683cb8c4fb218b6e5dc2f16e
timeCreated: 1504706738
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,87 @@
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace VLB_Samples
{
public class LightGenerator : MonoBehaviour
{
[Range(1, 100)]
[SerializeField] int CountX = 10;
[Range(1, 100)]
[SerializeField] int CountY = 10;
[SerializeField] float OffsetUnits = 1;
[SerializeField] float PositionY = 1;
[SerializeField] bool NoiseEnabled = false;
[SerializeField] bool AddLight = true;
public void Generate()
{
for (int i = 0; i < CountX; ++i)
{
for (int j = 0; j < CountY; ++j)
{
GameObject gao = null;
if(AddLight)
gao = new GameObject("Light_" + i + "_" + j, typeof(Light), typeof(VLB.VolumetricLightBeamSD), typeof(Rotater));
else
gao = new GameObject("Light_" + i + "_" + j, typeof(VLB.VolumetricLightBeamSD), typeof(Rotater));
gao.transform.SetPositionAndRotation( new Vector3(i * OffsetUnits, PositionY, j * OffsetUnits),
Quaternion.Euler(Random.Range(-45, 45) + 90f, Random.Range(0, 360), 0));
var beam = gao.GetComponent<VLB.VolumetricLightBeamSD>();
if (AddLight)
{
var light = gao.GetComponent<Light>();
light.type = LightType.Spot;
light.color = new Color(Random.value, Random.value, Random.value, 1.0f);
light.range = Random.Range(3f, 8f);
light.intensity = Random.Range(0.2f, 5f);
light.spotAngle = Random.Range(10f, 90f);
if(VLB.Config.Instance.geometryOverrideLayer)
{
// remove the layer of the beams from the light's culling mask to prevent from breaking GPU Instancing
light.cullingMask = ~(1 << VLB.Config.Instance.geometryLayerID);
}
}
else
{
beam.color = new Color(Random.value, Random.value, Random.value, 1.0f);
beam.fallOffEnd = Random.Range(3f, 8f);
beam.spotAngle = Random.Range(10f, 90f);
}
beam.coneRadiusStart = Random.Range(0f, 0.1f);
beam.geomCustomSides = Random.Range(12, 36);
beam.fresnelPow = Random.Range(1, 7.5f);
beam.noiseMode = NoiseEnabled ? VLB.NoiseMode.WorldSpace : VLB.NoiseMode.Disabled;
var rotater = gao.GetComponent<Rotater>();
rotater.EulerSpeed = new Vector3(0, Random.Range(-500, 500), 0);
}
}
}
}
#if UNITY_EDITOR
[CustomEditor(typeof(LightGenerator))]
public class LightGeneratorEditor : Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
if (Application.isPlaying) return;
if (GUILayout.Button("Generate"))
{
(target as LightGenerator).Generate();
}
}
}
#endif
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 40a4b77a9b84c3040a81c0b7a629248a
timeCreated: 1507704560
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,18 @@
using UnityEngine;
using UnityEngine.Serialization;
namespace VLB_Samples
{
public class Rotater : MonoBehaviour
{
[FormerlySerializedAs("m_EulerSpeed")]
public Vector3 EulerSpeed = Vector3.zero;
void Update()
{
var euler = transform.rotation.eulerAngles;
euler += EulerSpeed * Time.deltaTime;
transform.rotation = Quaternion.Euler(euler);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 031dc173b8912b246aaed3b7e88df54e
timeCreated: 1504710999
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: