Skip to content

Commit

Permalink
Environment scenes
Browse files Browse the repository at this point in the history
  • Loading branch information
andybak committed Jul 2, 2024
1 parent 85c80d5 commit 1d30613
Show file tree
Hide file tree
Showing 199 changed files with 79,381 additions and 0 deletions.
115 changes: 115 additions & 0 deletions Assets/EnvironmentSetup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
using System;
using Newtonsoft.Json.Linq;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;

[ExecuteInEditMode]
public class EnvironmentSetup : MonoBehaviour
{
public TextAsset m_EnvironmentJson;
public string m_Guid;

[ContextMenu("Apply Environment")]
void ApplyEnvironment()
{
Color getColor(JToken jToken)
{
float r = jToken["r"].Value<float>();
float g = jToken["g"].Value<float>();
float b = jToken["b"].Value<float>();
float a = jToken["a"].Value<float>();
return new Color(r, g, b, a);
}

Vector3 getVector3(JToken jToken)
{
float x = jToken["x"].Value<float>();
float y = jToken["y"].Value<float>();
float z = jToken["z"].Value<float>();
return new Vector3(x, y, z);
}

var environments = JObject.Parse(m_EnvironmentJson.text);
var environment = environments[m_Guid];
var renderSettings = environment["renderSettings"];
string skyboxName = renderSettings["skyboxCubemap"]?.Value<string>();
if (String.IsNullOrEmpty(skyboxName))
{
skyboxName = "SkyboxGradient";
}
var skyboxPath = $"Packages/com.icosa.open-brush-unity-tools/Runtime/Environments/Materials/Skies/{skyboxName}.mat";
var mat = (Material)AssetDatabase.LoadAssetAtPath(skyboxPath, typeof(Material));
mat.name = skyboxName;
RenderSettings.skybox = mat;
if (skyboxName == "SkyboxGradient")
{
RenderSettings.skybox.SetColor("_ColorA", getColor(environment["skyboxColorA"]));
RenderSettings.skybox.SetColor("_ColorB", getColor(environment["skyboxColorB"]));
}
else
{
RenderSettings.skybox.SetFloat("_Exposure", renderSettings["skyboxExposure"].Value<float>());
RenderSettings.skybox.SetColor("_Tint", getColor(renderSettings["skyboxTint"]));
}

var reflectTexName = renderSettings["reflectionCubemap"]?.Value<string>();
if (reflectTexName != null)
{
Cubemap tex;
var reflectionPath = $"Packages/com.icosa.open-brush-unity-tools/Runtime/Environments/Textures/Reflection Maps/{reflectTexName}";
tex = (Cubemap)AssetDatabase.LoadAssetAtPath($"{reflectionPath}.exr", typeof(Cubemap));
if (tex == null)
{
tex = (Cubemap)AssetDatabase.LoadAssetAtPath($"{reflectionPath}.png", typeof(Cubemap));
if (tex == null)
{
tex = (Cubemap)AssetDatabase.LoadAssetAtPath($"{reflectionPath}.jpeg", typeof(Cubemap));
}
}
if (tex != null)
{
tex.name = reflectTexName;
RenderSettings.customReflection = tex;
}
else
{
Debug.LogWarning($"Reflection cubemap not found: {reflectTexName}");
}
}

RenderSettings.reflectionIntensity = renderSettings["reflectionIntensity"].Value<float>();
RenderSettings.fog = renderSettings["fogEnabled"].Value<bool>();
RenderSettings.fogMode = FogMode.Exponential;
RenderSettings.fogColor = getColor(renderSettings["fogColor"]);
RenderSettings.fogDensity = renderSettings["fogDensity"].Value<float>();
RenderSettings.fogStartDistance = renderSettings["fogStartDistance"].Value<float>();
RenderSettings.fogEndDistance = renderSettings["fogEndDistance"].Value<float>();
RenderSettings.ambientSkyColor = getColor(renderSettings["ambientColor"]);

var camera = GetComponentInChildren<Camera>();
camera.clearFlags = CameraClearFlags.Skybox;
camera.backgroundColor = getColor(renderSettings["clearColor"]);

var lights = GetComponentsInChildren<Light>();
var envLights = environment["lights"];
for (var i = 0; i < lights.Length; i++)
{
var light = lights[i];
var envLight = envLights[i];
light.color = getColor(envLight["color"]);
light.transform.position = getVector3(envLight["position"]);
light.transform.rotation = Quaternion.Euler(getVector3(envLight["rotation"]));
light.type = (LightType)Enum.Parse(typeof(LightType), envLight["type"].Value<string>());
light.range = envLight["range"].Value<float>();
light.spotAngle = envLight["spotAngle"].Value<float>();
light.shadows = envLight["shadowsEnabled"].Value<bool>() ? LightShadows.Hard : LightShadows.None;
}

// TODO
// "environmentReverbZone": "EnvironmentAudio/ReverbZone_Arena",

EditorUtility.SetDirty(RenderSettings.skybox);
EditorSceneManager.MarkSceneDirty(gameObject.scene);
}
}
11 changes: 11 additions & 0 deletions Assets/EnvironmentSetup.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Packages/open-brush-unity-tools/Runtime/Environments.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
%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: AmbientGrid
m_Shader: {fileID: 4800000, guid: 85879211e00239541bb63f3b43929f20, type: 3}
m_ValidKeywords:
- _EMISSION
m_InvalidKeywords: []
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}
- _SpecGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _FarFadeDistance: 1
- _FarFadeDistanceEnd: 50
- _FarFadeDistanceStart: 30
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 0
- _NearFadeDistance: 1
- _NearFadeDistanceEnd: 20
- _NearFadeDistanceStart: 10
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 0.023529412, g: 0.023529412, b: 0.023529412, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.2, g: 0.2, b: 0.2, a: 1}
m_BuildTextureStacks: []

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
%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: BlackDoubleSided
m_Shader: {fileID: 4800000, guid: 828d37a5fcd68414cb8d1deb2c6a1e33, type: 3}
m_ValidKeywords: []
m_InvalidKeywords: []
m_LightmapFlags: 5
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: 2800000, guid: 57ec9586d21ff9142abf94cca6f69ef3, type: 3}
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_Ints: []
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _Glossiness: 0.5
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 0, g: 0, b: 0, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
m_BuildTextureStacks: []

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: DustMotes
m_Shader: {fileID: 4800000, guid: da1303cb40ad55a4684a109acab1a563, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 5
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _MainTex:
m_Texture: {fileID: 2800000, guid: 6b14dfad9d08fc34a936e2e721ac94ed, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BokehDistance: 20
- _Cutoff: 0.5
- _FadeDistance: 0.001
- _InvFade: 1
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _TintColor: {r: 0.296, g: 0.296, b: 0.296, a: 0.5}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1d30613

Please sign in to comment.