Skip to content

Commit

Permalink
More lighting and shadow control
Browse files Browse the repository at this point in the history
  • Loading branch information
Yan-K committed Dec 28, 2022
1 parent 71130f8 commit f7717c4
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 27 deletions.
18 changes: 2 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,6 @@ Made VRChat Avatar creation and testing easier

![Demo](https://i.imgur.com/mocsdzG.gif)

## TODO BEFORE REPO GOES PUBLIC

- [x] Change floor texture

- [ ] Add shadow color control (both shadow color and shadow strength)

- [ ] Add direct light control (color, intensity)

- [ ] Add floating point light

- [x] Add undo for slider

- [x] Implement NaughtyAttributes (maybe?)

## Features

Camera Control <br>
Expand All @@ -44,7 +30,7 @@ Change thumbnail for upload.

## Changelog

## v1.1 - 2022/12/28
### v1.1 - 2022/12/28

### Added

Expand All @@ -62,7 +48,7 @@ Change thumbnail for upload.

- Changed floor texture

## v1.0 - 2022/12/27
### v1.0 - 2022/12/27

Inital Release.

Expand Down
126 changes: 117 additions & 9 deletions SceneTemplate/Scripts/SceneController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.PostProcessing;
using NaughtyAttributes;

Expand All @@ -17,11 +18,13 @@ public class SceneController : MonoBehaviour

// ----------------- Camera Settings
[HorizontalLine(color: EColor.Gray)]
[Range(0.1f, 3f)]
[OnValueChanged("OnCameraScaleChanged")]
[Range(0.1f, 3.0f)]
[SerializeField]
internal float cameraHeight = 1.0f;

[Range(0.1f, 3f)]
[OnValueChanged("OnCameraScaleChanged")]
[Range(0.1f, 3.0f)]
[SerializeField]
internal float cameraDistance = 1.0f;

Expand All @@ -35,16 +38,38 @@ public class SceneController : MonoBehaviour
[HorizontalLine(color: EColor.Gray)]
[OnValueChanged("OnLightingRotationChanged")]
[Label("Lighting Horizontal")]
[Range(-180.0f, 180f)]
[Range(-180.0f, 180.0f)]
[SerializeField]
internal float directLightHorizontal = 120.0f;

[OnValueChanged("OnLightingRotationChanged")]
[Label("Lighting Vertical")]
[Range(-180.0f, 180f)]
[Range(-180.0f, 180.0f)]
[SerializeField]
internal float directLightVertical = 50.0f;

[OnValueChanged("OnLightingIntensityChanged")]
[Label("Brightness")]
[Range(0.0f, 3.0f)]
[SerializeField]
internal float directLightIntensity = 1.0f;

[OnValueChanged("OnShadowStrengthChanged")]
[Label("Shadow")]
[Range(0.0f, 1.0f)]
[SerializeField]
internal float shadowIntensity = 0.8f;

[OnValueChanged("OnLightingColorChanged")]
[Label("Lighting Color")]
[SerializeField]
internal Color directLightColor = Color.white;

[OnValueChanged("OnAmbientColorChanged")]
[Label("Ambient Color")]
[SerializeField]
internal Color ambientColor = new Color(0.19f, 0.19f, 0.19f, 1.0f);

// ----------------- Post Processing Settings
[HorizontalLine(color: EColor.Gray)]
[OnValueChanged("OnPostToggle")]
Expand All @@ -58,9 +83,9 @@ public class SceneController : MonoBehaviour
[SerializeField]
internal int postDropdown;


// ----------------- Thumbnail Settings
[HorizontalLine(color: EColor.Gray)]
[OnValueChanged("OnThumbnialTextureChanged")]
[ShowAssetPreview(128, 128)]
[SerializeField]
internal Texture thumbnailTexture;
Expand All @@ -75,6 +100,10 @@ public class SceneController : MonoBehaviour
[ShowIf("internalSettingsWarning")]
[SerializeField]
internal GameObject cameraParentObject;

[ShowIf("internalSettingsWarning")]
[SerializeField]
internal GameObject cameraObject;

[ShowIf("internalSettingsWarning")]
[SerializeField]
Expand All @@ -96,6 +125,33 @@ public class SceneController : MonoBehaviour
[SerializeField]
internal GameObject[] cameraObjects;

// ----------------- Reset
[Button]
internal void ResetCameraSettings()
{
cameraHeight = 1.0f;
cameraDistance = 1.0f;
cameraDropdown = 0;
OnCameraScaleChanged();
OnCameraSwitch();
}

[Button]
internal void ResetLightingSettings()
{
directLightHorizontal = 120.0f;
directLightVertical = 50.0f;
directLightIntensity = 1.0f;
shadowIntensity = 0.8f;
directLightColor = Color.white;
ambientColor = new Color(0.19f, 0.19f, 0.19f, 1.0f);
OnLightingRotationChanged();
OnLightingIntensityChanged();
OnLightingColorChanged();
OnShadowStrengthChanged();
OnAmbientColorChanged();
}

// ----------------- Generic Function
internal void ToggleObjects(GameObject[] targets, int index)
{
Expand All @@ -105,46 +161,98 @@ internal void ToggleObjects(GameObject[] targets, int index)

internal void OnCameraSwitch()
{
Undo.RecordObjects(cameraObjects, "Camera Switch");
ToggleObjects(cameraObjects, cameraDropdown);
}

internal void OnPostSwitch()
{
Undo.RecordObjects(postObjects, "Post Processing Switch");
ToggleObjects(postObjects, postDropdown);
}

internal void OnPostToggle()
{
Undo.RecordObject(postParentObject, "Post Processing Toggle");
postParentObject.SetActive(postToggle);
}

internal void OnCameraScaleChanged()
{
var newScale = new Vector3 (1.0f, 1.0f, 1.0f);
newScale.x = cameraDistance;
newScale.z = cameraDistance;
newScale.y = cameraHeight;

Undo.RecordObject(cameraParentObject.transform, "Camera Position");
cameraParentObject.transform.localScale = newScale;
}

internal void OnLightingRotationChanged()
{
var rotation = new Vector3 (0.0f, 0.0f, 0.0f);
rotation.x = directLightVertical;
rotation.y = directLightHorizontal;
rotation.z = 0.0f;

Undo.RecordObject(directLightObject.transform, "Lighting Rotation");
directLightObject.transform.localEulerAngles = rotation;
}

internal void OnLightingIntensityChanged()
{
Light target = directLightObject.GetComponent<Light>();

Undo.RecordObject(target, "Lighting Settings");
target.intensity = directLightIntensity;
}

internal void OnLightingColorChanged()
{
Light target = directLightObject.GetComponent<Light>();

Undo.RecordObject(target, "Lighting Settings");
target.color = directLightColor;
}

internal void OnShadowStrengthChanged()
{
Light target = directLightObject.GetComponent<Light>();

Undo.RecordObject(target, "Shadow Settings");
target.shadowStrength = shadowIntensity;
}

internal void OnAmbientColorChanged()
{
Camera targetBackground = cameraObject.GetComponent<Camera>();

Undo.RecordObject(targetBackground, "Ambient Settings");
targetBackground.backgroundColor = ambientColor;
RenderSettings.ambientLight = ambientColor;
}

internal void OnThumbnialTextureChanged()
{
thumbnailObject.GetComponent<Renderer>().sharedMaterial.SetTexture("_MainTex", thumbnailTexture);
}

// ----------------- Fields
internal DropdownList<int> CameraList()
{
return new DropdownList<int>()
{
{"Face01", 0}, {"Face02", 1}, {"Face03", 2},
{"Body01", 3}, {"Body02", 4}, {"Body03", 5}, {"Body04", 6},
{"Back01", 7}, {"Back02", 8}, {"Back03", 9}
{"Face 01", 0}, {"Face 02", 1}, {"Face 03", 2},
{"Body 01", 3}, {"Body 02", 4}, {"Body 03", 5}, {"Body 04", 6},
{"Back 01", 7}, {"Back 02", 8}, {"Back 03", 9}
};
}

internal DropdownList<int> PostList()
{
return new DropdownList<int>()
{
{"Post01", 0}, {"Post02", 1}, {"Post03", 2},
{"Post 01", 0}, {"Post 02", 1}, {"Post 03", 2},
};
}

Expand Down
9 changes: 7 additions & 2 deletions SceneTemplate/_Template.unity
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ RenderSettings:
m_FogDensity: 0.01
m_LinearFogStart: 0
m_LinearFogEnd: 300
m_AmbientSkyColor: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
m_AmbientSkyColor: {r: 0.19, g: 0.19, b: 0.19, a: 1}
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
m_AmbientIntensity: 1
Expand Down Expand Up @@ -156,11 +156,16 @@ MonoBehaviour:
cameraDropdown: 0
directLightHorizontal: 120
directLightVertical: 50
directLightIntensity: 1
shadowIntensity: 0.8
directLightColor: {r: 1, g: 1, b: 1, a: 1}
ambientColor: {r: 0.19, g: 0.19, b: 0.19, a: 1}
postToggle: 1
postDropdown: 0
thumbnailTexture: {fileID: 2800000, guid: b36b3dd83c8317d478450a61ac7701c5, type: 3}
internalSettingsWarning: 0
cameraParentObject: {fileID: 1409667018}
cameraObject: {fileID: 1761059475}
directLightObject: {fileID: 514919380}
postParentObject: {fileID: 225756816}
thumbnailObject: {fileID: 1080912098}
Expand Down Expand Up @@ -2065,7 +2070,7 @@ Camera:
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: 0.21960786, g: 0.21960786, b: 0.21960786, a: 1}
m_BackGroundColor: {r: 0.19, g: 0.19, b: 0.19, a: 1}
m_projectionMatrixMode: 1
m_GateFitMode: 2
m_FOVAxisMode: 0
Expand Down

0 comments on commit f7717c4

Please sign in to comment.