Skip to content
Permalink
Browse files

initial commit

  • Loading branch information...
aszecsei committed Feb 18, 2016
1 parent 43c9422 commit 603a05cf2679c7bd2ddb92875059695a4eb74a4e
Showing with 600 additions and 0 deletions.
  1. +9 −0 2D Volumetric Lighting/Materials.meta
  2. BIN 2D Volumetric Lighting/Materials/LightShaftMaterial.mat
  3. +8 −0 2D Volumetric Lighting/Materials/LightShaftMaterial.mat.meta
  4. BIN 2D Volumetric Lighting/Materials/Light_Material.mat
  5. +8 −0 2D Volumetric Lighting/Materials/Light_Material.mat.meta
  6. +9 −0 2D Volumetric Lighting/Prefabs.meta
  7. BIN 2D Volumetric Lighting/Prefabs/Light_Texture.prefab
  8. +8 −0 2D Volumetric Lighting/Prefabs/Light_Texture.prefab.meta
  9. BIN 2D Volumetric Lighting/Prefabs/Main Camera.prefab
  10. +8 −0 2D Volumetric Lighting/Prefabs/Main Camera.prefab.meta
  11. BIN 2D Volumetric Lighting/Prefabs/Platform1.prefab
  12. +8 −0 2D Volumetric Lighting/Prefabs/Platform1.prefab.meta
  13. +9 −0 2D Volumetric Lighting/Scripts.meta
  14. +131 −0 2D Volumetric Lighting/Scripts/LightShafter.cs
  15. +12 −0 2D Volumetric Lighting/Scripts/LightShafter.cs.meta
  16. +36 −0 2D Volumetric Lighting/Scripts/LightingCamera.cs
  17. +12 −0 2D Volumetric Lighting/Scripts/LightingCamera.cs.meta
  18. +70 −0 2D Volumetric Lighting/Scripts/MainCamera.cs
  19. +12 −0 2D Volumetric Lighting/Scripts/MainCamera.cs.meta
  20. +9 −0 2D Volumetric Lighting/Shaders.meta
  21. +62 −0 2D Volumetric Lighting/Shaders/AdditivePlusColor.shader
  22. +9 −0 2D Volumetric Lighting/Shaders/AdditivePlusColor.shader.meta
  23. +9 −0 2D Volumetric Lighting/Sprites.meta
  24. BIN 2D Volumetric Lighting/Sprites/Light_Emissive.psd
  25. +57 −0 2D Volumetric Lighting/Sprites/Light_Emissive.psd.meta
  26. BIN 2D Volumetric Lighting/Sprites/Light_Texture.psd
  27. +57 −0 2D Volumetric Lighting/Sprites/Light_Texture.psd.meta
  28. BIN 2D Volumetric Lighting/Sprites/Platform1_Texture.psd
  29. +57 −0 2D Volumetric Lighting/Sprites/Platform1_Texture.psd.meta

Some generated files are not rendered by default. Learn more.

Binary file not shown.

Some generated files are not rendered by default. Learn more.

Binary file not shown.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Binary file not shown.

Some generated files are not rendered by default. Learn more.

Binary file not shown.

Some generated files are not rendered by default. Learn more.

Binary file not shown.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

@@ -0,0 +1,131 @@
using UnityEngine;
using System.Collections;

public class LightShafter : MonoBehaviour {

// The number of rays to draw
[SerializeField]
[Range(1, 720)]
public int numberOfRays = 720;

public float lightDistance = 5;

[SerializeField]
[Range(-360, 360)]
public float lightAngle = -90;

[SerializeField]
[Range(0, 360)]
public float lightCone = 90;

[SerializeField]
public float lightSourceSize = 0;

public LayerMask layerMask;

public bool DrawDebugRays = true;

public Color lightColor = Color.white;

private GameObject[] shafts;

public Material shaftMaterial;

public GameObject PointLight;

[Range(0, 1)]
public float shaftWidth = 0.2f;

void Start()
{
Vector3 initialLocation = transform.position + (new Vector3(Mathf.Cos(Mathf.Deg2Rad * (lightAngle - 90)), Mathf.Sin(Mathf.Deg2Rad * (lightAngle - 90))) * lightSourceSize / 2);
Vector3 locationOffset = new Vector3(Mathf.Cos(Mathf.Deg2Rad * (lightAngle - 90)), Mathf.Sin(Mathf.Deg2Rad * (lightAngle - 90))) * lightSourceSize / numberOfRays;
float RaySpacing = lightCone / numberOfRays;
float initialAngle = lightAngle - (lightCone / 2);

PointLight.GetComponent<Light>().color = lightColor;

shafts = new GameObject[numberOfRays];
for (int i = 0; i < numberOfRays; i++)
{
shafts[i] = new GameObject();
shafts[i].name = "LightShaft " + (i + 1);
shafts[i].transform.parent = transform;
shafts[i].transform.position = transform.position;
shafts[i].layer = LayerMask.NameToLayer("Light");
LineRenderer shaftRenderer = shafts[i].AddComponent<LineRenderer>();
shaftRenderer.useWorldSpace = true;
shaftRenderer.material = shaftMaterial;
shaftRenderer.receiveShadows = false;
shaftRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
shaftRenderer.SetWidth(locationOffset.magnitude, shaftWidth);
shaftRenderer.SetColors(lightColor, Color.black);

Vector3 origin = initialLocation - (locationOffset * i);
Vector3 direction = new Vector3(Mathf.Cos(Mathf.Deg2Rad * (i * RaySpacing + initialAngle)) * lightDistance, Mathf.Sin(Mathf.Deg2Rad * (i * RaySpacing + initialAngle)) * lightDistance);

shaftRenderer.SetPosition(0, origin);
shaftRenderer.SetPosition(1, origin + direction);
}
}

void LateUpdate()
{
float RaySpacing = lightCone / numberOfRays;
float initialAngle = lightAngle - (lightCone / 2);

Vector3 initialLocation = transform.position + (new Vector3(Mathf.Cos(Mathf.Deg2Rad * (lightAngle - 90)), Mathf.Sin(Mathf.Deg2Rad * (lightAngle - 90))) * lightSourceSize / 2);
Vector3 locationOffset = new Vector3(Mathf.Cos(Mathf.Deg2Rad * (lightAngle - 90)), Mathf.Sin(Mathf.Deg2Rad * (lightAngle - 90))) * lightSourceSize / numberOfRays;

for (int i = 0; i < numberOfRays; i++)
{
Vector3 origin = initialLocation - (locationOffset * i);
Vector3 direction = new Vector3(Mathf.Cos(Mathf.Deg2Rad * (i * RaySpacing + initialAngle)) * lightDistance, Mathf.Sin(Mathf.Deg2Rad * (i * RaySpacing + initialAngle)) * lightDistance);
RaycastHit2D hit = Physics2D.Raycast(origin, direction, lightDistance, layerMask);

float travelledDistance = lightDistance;

LineRenderer shaftRenderer = shafts[i].GetComponent<LineRenderer>();

if (hit)
{
travelledDistance = hit.distance;
}

float distanceFrac = travelledDistance / lightDistance;

shaftRenderer.SetWidth(locationOffset.magnitude, locationOffset.magnitude + ((shaftWidth - locationOffset.magnitude) * distanceFrac));
shaftRenderer.SetColors(lightColor, new Color(lightColor.r * (1 - distanceFrac), lightColor.g * (1 - distanceFrac), lightColor.b * (1 - distanceFrac)));

shaftRenderer.SetPosition(0, origin);
shaftRenderer.SetPosition(1, origin + (direction * distanceFrac));
}
}

void OnDrawGizmos()
{
if (DrawDebugRays)
{
float RaySpacing = lightCone / numberOfRays;
float initialAngle = lightAngle - (lightCone / 2);

Vector3 initialLocation = transform.position + (new Vector3(Mathf.Cos(Mathf.Deg2Rad * (lightAngle - 90)), Mathf.Sin(Mathf.Deg2Rad * (lightAngle - 90))) * lightSourceSize / 2);
Vector3 locationOffset = new Vector3(Mathf.Cos(Mathf.Deg2Rad * (lightAngle - 90)), Mathf.Sin(Mathf.Deg2Rad * (lightAngle - 90))) * lightSourceSize / numberOfRays;

for (int i = 0; i < numberOfRays; i++)
{
Vector3 origin = initialLocation - (locationOffset * i);
Vector3 direction = new Vector3(Mathf.Cos(Mathf.Deg2Rad * (i * RaySpacing + initialAngle)) * lightDistance, Mathf.Sin(Mathf.Deg2Rad * (i * RaySpacing + initialAngle)) * lightDistance);
RaycastHit2D hit = Physics2D.Raycast(origin, direction, lightDistance, layerMask);
if (hit)
{
Gizmos.DrawRay(origin, (direction * hit.distance / lightDistance));
}
else
{
Gizmos.DrawRay(origin, direction);
}
}
}
}
}

Some generated files are not rendered by default. Learn more.

@@ -0,0 +1,36 @@
using UnityEngine;
using System.Collections;

public class LightingCamera : MonoBehaviour {

protected int width;
protected int height;
protected RenderTexture target;
protected Camera camComponent;

void Start()
{
camComponent = GetComponent<Camera>();
target = new RenderTexture(Screen.width, Screen.height, 0);
width = Screen.width;
height = Screen.height;
target.name = "TextureFromCamera_" + gameObject.name;
target.Create();
camComponent.targetTexture = target;
}

void Update()
{
if (width != Screen.width || height != Screen.height)
{
target.Release();
Destroy(target);
target = new RenderTexture(Screen.width, Screen.height, 0);
width = Screen.width;
height = Screen.height;
target.name = "TextureFromCamera_" + gameObject.name;
target.Create();
camComponent.targetTexture = target;
}
}
}

Some generated files are not rendered by default. Learn more.

@@ -0,0 +1,70 @@
using System;
using UnityEngine;

namespace UnityStandardAssets.ImageEffects
{
[ExecuteInEditMode]
[RequireComponent(typeof(Camera))]
[AddComponentMenu("Image Effects/Custom/Main Camera Overlay")]
public class MainCamera : PostEffectsBase
{
public enum OverlayBlendMode
{
Additive = 0,
ScreenBlend = 1,
Multiply = 2,
Overlay = 3,
AlphaBlend = 4,
}

public OverlayBlendMode blendMode = OverlayBlendMode.Overlay;
public float intensity = 1.0f;

public Shader overlayShader = null;
private Material overlayMaterial = null;

public Camera lightingCamera;


public override bool CheckResources()
{
CheckSupport(false);

overlayMaterial = CheckShaderAndCreateMaterial(overlayShader, overlayMaterial);

if (!isSupported)
ReportAutoDisable();
return isSupported;
}

void OnRenderImage(RenderTexture source, RenderTexture destination)
{
if (CheckResources() == false)
{
Graphics.Blit(source, destination);
return;
}

Vector4 UV_Transform = new Vector4(1, 0, 0, 1);

#if UNITY_WP8
// WP8 has no OS support for rotating screen with device orientation,
// so we do those transformations ourselves.
if (Screen.orientation == ScreenOrientation.LandscapeLeft) {
UV_Transform = new Vector4(0, -1, 1, 0);
}
if (Screen.orientation == ScreenOrientation.LandscapeRight) {
UV_Transform = new Vector4(0, 1, -1, 0);
}
if (Screen.orientation == ScreenOrientation.PortraitUpsideDown) {
UV_Transform = new Vector4(-1, 0, 0, -1);
}
#endif

overlayMaterial.SetVector("_UV_Transform", UV_Transform);
overlayMaterial.SetFloat("_Intensity", intensity);
overlayMaterial.SetTexture("_Overlay", lightingCamera.targetTexture);
Graphics.Blit(source, destination, overlayMaterial, (int)blendMode);
}
}
}

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

0 comments on commit 603a05c

Please sign in to comment.
You can’t perform that action at this time.