summaryrefslogtreecommitdiff
path: root/SurvivalTest/Assets/ACS-17/LightCone - Volumetric Spotlight
diff options
context:
space:
mode:
Diffstat (limited to 'SurvivalTest/Assets/ACS-17/LightCone - Volumetric Spotlight')
-rw-r--r--SurvivalTest/Assets/ACS-17/LightCone - Volumetric Spotlight/LightCone.cs215
-rw-r--r--SurvivalTest/Assets/ACS-17/LightCone - Volumetric Spotlight/LightCone.cs.meta12
-rw-r--r--SurvivalTest/Assets/ACS-17/LightCone - Volumetric Spotlight/Mat Additive Light Cone.mat78
-rw-r--r--SurvivalTest/Assets/ACS-17/LightCone - Volumetric Spotlight/Mat Additive Light Cone.mat.meta8
-rw-r--r--SurvivalTest/Assets/ACS-17/LightCone - Volumetric Spotlight/UnlitOverlay.shader30
-rw-r--r--SurvivalTest/Assets/ACS-17/LightCone - Volumetric Spotlight/UnlitOverlay.shader.meta9
6 files changed, 352 insertions, 0 deletions
diff --git a/SurvivalTest/Assets/ACS-17/LightCone - Volumetric Spotlight/LightCone.cs b/SurvivalTest/Assets/ACS-17/LightCone - Volumetric Spotlight/LightCone.cs
new file mode 100644
index 0000000..edfc47d
--- /dev/null
+++ b/SurvivalTest/Assets/ACS-17/LightCone - Volumetric Spotlight/LightCone.cs
@@ -0,0 +1,215 @@
+#define LightCone_OnDrawGizmos_Collide
+
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+[RequireComponent( typeof(Light) )]
+public class LightCone : MonoBehaviour {
+ public int wedges = 36;
+ public float dist = 20;
+ public float width = 2;
+ public float height = 2;
+ [SerializeField]
+ private Color _color = new Color(1, 1, 1, 0.25f);
+ public LayerMask collidesWith;
+ public int gizmoWedges = 4;
+
+ [Header("Spotlight Settings")]
+ public bool spotlightEnabled = true;
+ public float spotAnglePercent = 100;
+ public float rangePercent = 100;
+
+
+
+ MeshFilter mF;
+ Mesh m;
+ Vector3[] verts;
+ int[] tris;
+ Material mat;
+ RaycastHit[] hits;
+
+ private Light lt;
+ private float dist0, width0, sAP0, rP0;
+
+ public Color color
+ {
+ get
+ {
+ return _color;
+ }
+
+ set
+ {
+ _color = value;
+ UpdateLight();
+ }
+ }
+
+ // Use this for initialization
+ void Start () {
+ mF = GetComponent<MeshFilter>();
+ m = mF.mesh;
+
+ m.Clear();
+
+ MakeVerts();
+
+ tris = new int[wedges*3];
+
+ int triN=0;
+ int vertN=1;
+ for (int i=0; i<wedges; i++) {
+ tris[triN] = 0;
+ triN++;
+ if (vertN < verts.Length-1) {
+ tris[triN] = vertN+1;
+ } else {
+ tris[triN] = 1;
+ }
+ triN++;
+ tris[triN] = vertN;
+ vertN++;
+ triN++;
+ }
+ m.triangles = tris;
+
+ mat = GetComponent<Renderer>().material;
+
+ UpdateLight();
+ }
+
+ void MakeVerts() {
+ verts = new Vector3[wedges+1];
+ verts[0] = Vector3.zero;
+
+ Vector3 v, r;
+ hits = new RaycastHit[wedges];
+ for (int i=0; i<wedges; i++) {
+ v = Vector3.zero;
+ v.z = dist;
+ v.x = Mathf.Cos(i * Mathf.PI * 2 / wedges) * width;
+ v.y = Mathf.Sin(i * Mathf.PI * 2 / wedges) * height;
+ r = transform.rotation * v.normalized;
+ if ( Physics.Raycast(transform.position, r, out hits[i], v.magnitude, collidesWith) ) {
+ v = v.normalized * hits[i].distance;
+ }
+ verts[i+1] = v;
+ }
+ m.vertices = verts;
+ }
+
+ // Update is called once per frame
+ void Update () {
+ MakeVerts();
+ if (color != mat.color) {
+ mat.color = color;
+ }
+ }
+
+ // This draws the outline when not playing (and Selected)
+ void OnDrawGizmosSelected() {
+ if (Application.isPlaying) return;
+ Vector3[] pts = new Vector3[gizmoWedges];
+ Vector3 v, vDir;
+
+ Color litColor = color;
+ litColor.a = 1;
+#if LightCone_OnDrawGizmos_Collide
+ Color grayColor = Color.Lerp(Color.clear, color, 0.5f);
+ grayColor.a = 0.5f;
+#else
+ Gizmos.color = litColor;
+#endif
+
+ for (int i=0; i<gizmoWedges; i++) {
+ v = Vector3.zero;
+ v.z = dist;
+ v.x = Mathf.Cos(i * Mathf.PI * 2 / gizmoWedges) * width;
+ v.y = Mathf.Sin(i * Mathf.PI * 2 / gizmoWedges) * height;
+ vDir = transform.rotation * v;
+ pts[i] = vDir;
+ pts[i] += transform.position;
+
+#if LightCone_OnDrawGizmos_Collide
+#else
+ Gizmos.DrawLine(transform.position, pts[i]);
+ if (i>0) {
+ Gizmos.DrawLine(pts[i-1], pts[i]);
+ if (i == gizmoWedges-1) {
+ Gizmos.DrawLine(pts[i], pts[0]);
+ }
+ }
+#endif
+ }
+
+#if LightCone_OnDrawGizmos_Collide
+ Vector3[] ptsColl = new Vector3[gizmoWedges];
+ RaycastHit hitInfo;
+ for (int i = 0; i < pts.Length; i++) {
+ ptsColl[i] = pts[i];
+ vDir = ptsColl[i] - transform.position;
+ if (Physics.Raycast(transform.position, vDir, out hitInfo, vDir.magnitude, collidesWith))
+ {
+ // The line collided with something, so make it shorter
+ ptsColl[i] = hitInfo.point;
+ }
+
+ // Draw the area past the collision
+ Gizmos.color = grayColor;
+ Gizmos.DrawLine(ptsColl[i], pts[i]);
+ if (i > 0)
+ {
+ Gizmos.DrawLine(pts[i - 1], pts[i]);
+ if (i == gizmoWedges - 1)
+ {
+ Gizmos.DrawLine(pts[i], pts[0]);
+ }
+ }
+ // Draw the collision
+ Gizmos.color = litColor;
+ Gizmos.DrawLine(transform.position, ptsColl[i]);
+ if (i > 0)
+ {
+ Gizmos.DrawLine(ptsColl[i - 1], ptsColl[i]);
+ if (i == gizmoWedges - 1)
+ {
+ Gizmos.DrawLine(ptsColl[i], ptsColl[0]);
+ }
+ }
+ }
+#endif
+
+ }
+
+ private void OnDrawGizmos()
+ {
+ if (Application.isPlaying) return;
+ UpdateLight();
+ }
+
+ void UpdateLight() {
+ if (lt == null) {
+ lt = GetComponent<Light>();
+ lt.type = LightType.Spot;
+ }
+
+ if (dist0 != dist || width0 != width || sAP0 != spotAnglePercent || rangePercent != rP0) {
+ lt.spotAngle = Mathf.Atan2(width, dist)*360/Mathf.PI * (spotAnglePercent / 100f);
+ lt.range = dist * rangePercent / 100f;
+ dist0 = dist;
+ width0 = width;
+ sAP0 = spotAnglePercent;
+ rP0 = rangePercent;
+ }
+
+ lt.color = color;
+
+ lt.enabled = spotlightEnabled;
+ }
+
+
+ public RaycastHit[] GetRaycastHits() {
+ return hits;
+ }
+}
diff --git a/SurvivalTest/Assets/ACS-17/LightCone - Volumetric Spotlight/LightCone.cs.meta b/SurvivalTest/Assets/ACS-17/LightCone - Volumetric Spotlight/LightCone.cs.meta
new file mode 100644
index 0000000..b6d5b63
--- /dev/null
+++ b/SurvivalTest/Assets/ACS-17/LightCone - Volumetric Spotlight/LightCone.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 9bf7c6c658d9540758d0723c6dc6bcbb
+timeCreated: 1485975479
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/SurvivalTest/Assets/ACS-17/LightCone - Volumetric Spotlight/Mat Additive Light Cone.mat b/SurvivalTest/Assets/ACS-17/LightCone - Volumetric Spotlight/Mat Additive Light Cone.mat
new file mode 100644
index 0000000..57d67cb
--- /dev/null
+++ b/SurvivalTest/Assets/ACS-17/LightCone - Volumetric Spotlight/Mat Additive Light Cone.mat
@@ -0,0 +1,78 @@
+%YAML 1.1
+%TAG !u! tag:unity3d.com,2011:
+--- !u!21 &2100000
+Material:
+ serializedVersion: 6
+ m_ObjectHideFlags: 0
+ m_PrefabParentObject: {fileID: 0}
+ m_PrefabInternal: {fileID: 0}
+ m_Name: Mat Additive Light Cone
+ m_Shader: {fileID: 4800000, guid: f0ca8b647c0774e14b8fd3ccdede1fde, type: 3}
+ m_ShaderKeywords: _EMISSION
+ m_LightmapFlags: 1
+ m_EnableInstancingVariants: 0
+ m_DoubleSidedGI: 0
+ m_CustomRenderQueue: -1
+ stringTagMap: {}
+ disabledShaderPasses: []
+ m_SavedProperties:
+ serializedVersion: 3
+ m_TexEnvs:
+ - _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}
+ m_Floats:
+ - _BumpScale: 1
+ - _Cutoff: 0.5
+ - _DetailNormalMapScale: 1
+ - _DstBlend: 0
+ - _GlossMapScale: 1
+ - _Glossiness: 0.5
+ - _GlossyReflections: 1
+ - _InvFade: 1
+ - _Metallic: 0
+ - _Mode: 0
+ - _OcclusionStrength: 1
+ - _Parallax: 0.02
+ - _SmoothnessTextureChannel: 0
+ - _SpecularHighlights: 1
+ - _SrcBlend: 1
+ - _UVSec: 0
+ - _ZWrite: 1
+ m_Colors:
+ - _Color: {r: 1, g: 1, b: 1, a: 1}
+ - _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
+ - _TintColor: {r: 0.5, g: 0.5, b: 0.5, a: 0.075}
diff --git a/SurvivalTest/Assets/ACS-17/LightCone - Volumetric Spotlight/Mat Additive Light Cone.mat.meta b/SurvivalTest/Assets/ACS-17/LightCone - Volumetric Spotlight/Mat Additive Light Cone.mat.meta
new file mode 100644
index 0000000..7699aec
--- /dev/null
+++ b/SurvivalTest/Assets/ACS-17/LightCone - Volumetric Spotlight/Mat Additive Light Cone.mat.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 8dc5a0d87fe0e40ecb35e453c3ad9be8
+timeCreated: 1485975020
+licenseType: Store
+NativeFormatImporter:
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/SurvivalTest/Assets/ACS-17/LightCone - Volumetric Spotlight/UnlitOverlay.shader b/SurvivalTest/Assets/ACS-17/LightCone - Volumetric Spotlight/UnlitOverlay.shader
new file mode 100644
index 0000000..eaaecec
--- /dev/null
+++ b/SurvivalTest/Assets/ACS-17/LightCone - Volumetric Spotlight/UnlitOverlay.shader
@@ -0,0 +1,30 @@
+Shader "Custom/UnlitOverlay"
+{
+ Properties
+ {
+ _Color ("Main Color", Color) = (1,1,1,1)
+ _MainTex ("Base (RGB) Trans. (Alpha)", 2D) = "white" { }
+ }
+
+ Category
+ {
+ ZWrite On
+ Blend SrcAlpha OneMinusSrcAlpha
+ SubShader
+ {
+ Tags { "Queue" = "Overlay" }
+ Pass
+ {
+ ZWrite Off
+ Cull Off
+ Lighting Off
+ SetTexture [_MainTex]
+ {
+ constantColor [_Color]
+ Combine texture * constant, texture * constant
+ }
+
+ }
+ }
+ }
+}
diff --git a/SurvivalTest/Assets/ACS-17/LightCone - Volumetric Spotlight/UnlitOverlay.shader.meta b/SurvivalTest/Assets/ACS-17/LightCone - Volumetric Spotlight/UnlitOverlay.shader.meta
new file mode 100644
index 0000000..eeef3f7
--- /dev/null
+++ b/SurvivalTest/Assets/ACS-17/LightCone - Volumetric Spotlight/UnlitOverlay.shader.meta
@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: f0ca8b647c0774e14b8fd3ccdede1fde
+timeCreated: 1485999609
+licenseType: Store
+ShaderImporter:
+ defaultTextures: []
+ userData:
+ assetBundleName:
+ assetBundleVariant: