Skip to content

Commit

Permalink
💼🪻 ↝ Adding high quality/realistic texture component of the generator…
Browse files Browse the repository at this point in the history
  • Loading branch information
Gizmotronn committed Jun 7, 2023
0 parents commit 207098c
Show file tree
Hide file tree
Showing 12,341 changed files with 754,097 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
Binary file added .DS_Store
Binary file not shown.
Binary file added immersive/.DS_Store
Binary file not shown.
Binary file added immersive/Assets/.DS_Store
Binary file not shown.
55 changes: 55 additions & 0 deletions immersive/Assets/ColourGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ColourGenerator {

ColourSettings settings;
Texture2D texture;
const int textureResolution = 50;

public void UpdateSettings(ColourSettings settings)
{
this.settings = settings;
if (texture == null || texture.height != settings.biomeColourSettings.biomes.Length) {
texture = new Texture2D(textureResolution, settings.biomeColourSettings.biomes.Length);
}
}

public void UpdateElevation(MinMax elevationMinMax) {
settings.planetMaterial.SetVector("_elevationMinMax", new Vector4(elevationMinMax.Min, elevationMinMax.Max));
}

public BiomePercentFromPoint(Vector3 pointOnUnitSphere) {
float heightPercent = (pointOnUnitSphere.y + 1 / 2f);
float biomeIndex = 0;
int numBiomes = settings.biomeColourSettings.biomes.length;

for (int i = 0; i < numBiomes; i++) {
if (settings.biomeColourSettings.biomes[i].startHeight < heightPercent) {
biomeIndex = i;
} else {
break;
}
}

return biomeIndex / Mathf.Max(1, numBiomes - 1);
}

public void UpdateColours()
{
Color[] colours = new Color[texture.width * texture.height];
int colourIndex = 0;
foreach (var biome in settings.biomeColourSettings.biomes) {
for (int i = 0; i < textureResolution; i++) {
Color gradientCol = biome.gradient.Evaluate(i / (textureResolution - 1f));
Color tintCol = biome.tint;
colours[colourIndex] = gradientCol * (1 - biome.tintPercent) + tintCol * biome.tintPercent;
colourIndex++;
}
}
texture.SetPixels(colours);
texture.Apply();
settings.planetMaterial.SetTexture("_texture", texture);
}
}
11 changes: 11 additions & 0 deletions immersive/Assets/ColourGenerator.cs.meta

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

24 changes: 24 additions & 0 deletions immersive/Assets/ColourSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu()]
public class ColourSettings : ScriptableObject {
public Material planetMaterial;
public BiomeColourSettings biomeColourSettings;

[System.Serializable]
public class BiomeColourSettings {
public Biome[] biomes;

[System.Serializable]
public class Biome {
public Gradient gradient;
public Color tint;
[Range(0,1)]
public float startHeight;
[Range(0,1)]
public float tintPercent;
}
}
}
11 changes: 11 additions & 0 deletions immersive/Assets/ColourSettings.cs.meta

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

29 changes: 29 additions & 0 deletions immersive/Assets/ConditionalHideAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using UnityEngine;
using System;
using System.Collections;

//Original version of the ConditionalHideAttribute created by Brecht Lecluyse (www.brechtos.com)
//Modified by: Sebastian Lague

[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property |
AttributeTargets.Class | AttributeTargets.Struct, Inherited = true)]
public class ConditionalHideAttribute : PropertyAttribute
{
public string conditionalSourceField;
public int enumIndex;

public ConditionalHideAttribute(string boolVariableName)
{
conditionalSourceField = boolVariableName;
}

public ConditionalHideAttribute(string enumVariableName, int enumIndex)
{
conditionalSourceField = enumVariableName;
this.enumIndex = enumIndex;
}

}



11 changes: 11 additions & 0 deletions immersive/Assets/ConditionalHideAttribute.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 immersive/Assets/Editor.meta

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

84 changes: 84 additions & 0 deletions immersive/Assets/Editor/ConditionalHidePropertyDrawer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;

//Original version of the ConditionalHideAttribute created by Brecht Lecluyse (www.brechtos.com)
//Modified by: Sebastian Lague

[CustomPropertyDrawer(typeof(ConditionalHideAttribute))]
public class ConditionalHidePropertyDrawer : PropertyDrawer
{

public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
ConditionalHideAttribute condHAtt = (ConditionalHideAttribute)attribute;
bool enabled = GetConditionalHideAttributeResult(condHAtt, property);

if (enabled)
{
EditorGUI.PropertyField(position, property, label, true);
}
}

public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
ConditionalHideAttribute condHAtt = (ConditionalHideAttribute)attribute;
bool enabled = GetConditionalHideAttributeResult(condHAtt, property);

if (enabled)
{
return EditorGUI.GetPropertyHeight(property, label);
}
//We want to undo the spacing added before and after the property
return -EditorGUIUtility.standardVerticalSpacing;

}

bool GetConditionalHideAttributeResult(ConditionalHideAttribute condHAtt, SerializedProperty property)
{
SerializedProperty sourcePropertyValue = null;

//Get the full relative property path of the sourcefield so we can have nested hiding.Use old method when dealing with arrays
if (!property.isArray)
{
string propertyPath = property.propertyPath; //returns the property path of the property we want to apply the attribute to
string conditionPath = propertyPath.Replace(property.name, condHAtt.conditionalSourceField); //changes the path to the conditionalsource property path
sourcePropertyValue = property.serializedObject.FindProperty(conditionPath);

//if the find failed->fall back to the old system
if (sourcePropertyValue == null)
{
//original implementation (doens't work with nested serializedObjects)
sourcePropertyValue = property.serializedObject.FindProperty(condHAtt.conditionalSourceField);
}
}
else
{
//original implementation (doens't work with nested serializedObjects)
sourcePropertyValue = property.serializedObject.FindProperty(condHAtt.conditionalSourceField);
}


if (sourcePropertyValue != null)
{
return CheckPropertyType(condHAtt,sourcePropertyValue);
}

return true;
}

bool CheckPropertyType(ConditionalHideAttribute condHAtt, SerializedProperty sourcePropertyValue)
{
//Note: add others for custom handling if desired
switch (sourcePropertyValue.propertyType)
{
case SerializedPropertyType.Boolean:
return sourcePropertyValue.boolValue;
case SerializedPropertyType.Enum:
return sourcePropertyValue.enumValueIndex == condHAtt.enumIndex;
default:
Debug.LogError("Data type of the property used for conditional hiding [" + sourcePropertyValue.propertyType + "] is currently not supported");
return true;
}
}
}
11 changes: 11 additions & 0 deletions immersive/Assets/Editor/ConditionalHidePropertyDrawer.cs.meta

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

61 changes: 61 additions & 0 deletions immersive/Assets/Editor/PlanetEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

[CustomEditor(typeof(Planet))]
public class PlanetEditor : Editor {

Planet planet;
Editor shapeEditor;
Editor colourEditor;

public override void OnInspectorGUI()
{
using (var check = new EditorGUI.ChangeCheckScope())
{
base.OnInspectorGUI();
if (check.changed)
{
planet.GeneratePlanet();
}
}

if (GUILayout.Button("Generate Planet"))
{
planet.GeneratePlanet();
}

DrawSettingsEditor(planet.shapeSettings, planet.OnShapeSettingsUpdated, ref planet.shapeSettingsFoldout, ref shapeEditor);
DrawSettingsEditor(planet.colourSettings, planet.OnColourSettingsUpdated, ref planet.colourSettingsFoldout, ref colourEditor);
}

void DrawSettingsEditor(Object settings, System.Action onSettingsUpdated, ref bool foldout, ref Editor editor)
{
if (settings != null)
{
foldout = EditorGUILayout.InspectorTitlebar(foldout, settings);
using (var check = new EditorGUI.ChangeCheckScope())
{
if (foldout)
{
CreateCachedEditor(settings, null, ref editor);
editor.OnInspectorGUI();

if (check.changed)
{
if (onSettingsUpdated != null)
{
onSettingsUpdated();
}
}
}
}
}
}

private void OnEnable()
{
planet = (Planet)target;
}
}
11 changes: 11 additions & 0 deletions immersive/Assets/Editor/PlanetEditor.cs.meta

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

37 changes: 37 additions & 0 deletions immersive/Assets/ForwardRenderer.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: de640fe3d0db1804a85f9fc8f5cadab6, type: 3}
m_Name: ForwardRenderer
m_EditorClassIdentifier:
m_RendererFeatures: []
m_RendererFeatureMap:
postProcessData: {fileID: 0}
shaders:
blitPS: {fileID: 0}
copyDepthPS: {fileID: 0}
screenSpaceShadowPS: {fileID: 0}
samplingPS: {fileID: 0}
fallbackErrorPS: {fileID: 0}
m_OpaqueLayerMask:
serializedVersion: 2
m_Bits: 4294967295
m_TransparentLayerMask:
serializedVersion: 2
m_Bits: 4294967295
m_DefaultStencilState:
overrideStencilState: 0
stencilReference: 0
stencilCompareFunction: 8
passOperation: 0
failOperation: 0
zFailOperation: 0
m_ShadowTransparentReceive: 1
8 changes: 8 additions & 0 deletions immersive/Assets/ForwardRenderer.asset.meta

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

8 changes: 8 additions & 0 deletions immersive/Assets/Graphics.meta

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

Loading

0 comments on commit 207098c

Please sign in to comment.