Add several test dollhouses to try to get this working

This commit is contained in:
gunnbr committed 2021-01-18 23:23:54 -08:00
1 parent 0f4ebbd14f
commit 320ee336ae
48 files changed
+8934 -184

No files matched your search

@@ -0,0 +1,89 @@
Shader "A2 Games/Advance Unlit"
{
Properties
{
//Main texturing
_MainTex ("Texture", 2D) = "white" {} //main texture to be used
_TintColor ("Tint Color", Color) = (1,1,1,1) //tint color that gets blends over the main texture
//Main texture secondary settings
[Enum(UnityEngine.Rendering.CullMode)] _Cull ("Culling Mode", Float) = 2 //Culling modes switch
[HideInInspector] _AlphaCutoff ("Alpha Cutoff", Range(0,1.01)) = 0.5 //Alpha cutoff value
//Specularity
_SpecularTex ("Specular", 2D) = "white" {} //Texture for specularity - Emission map
_SpecularColor ("Specular Color", Color) = (0,0,0,0) //Specular Color tint over specular texture
//Use to switch between different rendering modes or blend modes
[HideInInspector] _SrcBlend ("_SrcBlend", Float) = 1 //Source blend value
[HideInInspector] _DstBlend ("_DstBlend", Float) = 0 //Destination blend value
[HideInInspector] _ZWrite ("_ZWrite", Float) = 1 //Z-buffer write value
}
SubShader
{
Tags {"IgnoreProjector"="True"}
LOD 100
Blend [_SrcBlend] [_DstBlend] //Switch blend modes according to values
ZWrite [_ZWrite] //Switch this on or off according to value
Cull [_Cull] //Switching between culling modes
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
//For using render mode features mentioned in customGUI
#pragma shader_feature _ _RENDERING_CUTOUT _RENDERING_FADE _RENDERING_TRANSPARENT
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
//Variables intialization
sampler2D _MainTex;
float4 _MainTex_ST;
fixed4 _TintColor;
float _AlphaCutoff;
sampler2D _SpecularTex;
float4 _SpecularTex_ST;
fixed4 _SpecularColor;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex); //Transform textures
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv) * _TintColor; //Applying texture and blending it with the tint color
half3 emission = tex2D(_SpecularTex, i.uv).rgb * _SpecularColor.rgb; //Applying specularity and blending it with the specular color
col.rgb += emission; //blending it with the original texture
#if defined(_RENDERING_CUTOUT) //Only clip if rendering mode is cutout
clip(col.a - _AlphaCutoff); //Clipping
#endif
return col;
}
ENDCG
}
}
CustomEditor "AdvanceUnlitCustomGUI" //Custom GUI Script class
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 017a8025aa7dc144b916266fe8f1fb83
ShaderImporter:
externalObjects: {}
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 09e3f7a2e6dbbfa4e863035210602019
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,187 @@
using UnityEngine;
using UnityEditor;
using UnityEngine.Rendering;
public class AdvanceUnlitCustomGUI : ShaderGUI
{
enum RenderMode //All switchable render modes
{
Opaque, Cutout, Fade, Transparent
//Opaque = opacity 100%
//Cutout = Cutout only opaque parts and ignore the transparent parts
//Fade = Partial transparency or translucent or semi-transparent objects
//Trasnparent = Complete transparency
}
struct RenderSettings //Render settings for all render modes
{
public RenderQueue queue;
public string renderType;
public BlendMode srcBlend, dstBlend;
public bool zWrite;
public static RenderSettings[] modes = {
new RenderSettings() {
//Opaque render mode
queue = RenderQueue.Geometry,
renderType = "",
srcBlend = BlendMode.One,
dstBlend = BlendMode.Zero,
zWrite = true
},
new RenderSettings() {
//Cutout render mode
queue = RenderQueue.AlphaTest,
renderType = "TransparentCutout",
srcBlend = BlendMode.One,
dstBlend = BlendMode.Zero,
zWrite = true
},
new RenderSettings() {
//Fade render mode
queue = RenderQueue.Transparent,
renderType = "Transparent",
srcBlend = BlendMode.SrcAlpha,
dstBlend = BlendMode.OneMinusSrcAlpha,
zWrite = false
},
new RenderSettings() {
//Transparent render mode
queue = RenderQueue.Transparent,
renderType = "Transparent",
srcBlend = BlendMode.One,
dstBlend = BlendMode.OneMinusSrcAlpha,
zWrite = false
}
};
}
static GUIContent staticLabel = new GUIContent();
Material target;
MaterialEditor editor;
MaterialProperty[] properties;
bool showAlphaCutoff; //Determines whether to show alpha cutoff slider
//Main GUI function
public override void OnGUI(
MaterialEditor editor, MaterialProperty[] properties
)
{
this.target = editor.target as Material;
this.editor = editor;
this.properties = properties;
RunRenderModes(); //First put render mode option in the inspector
if (showAlphaCutoff)
{
SetAlphaCutoff(); //Set alpha cutoff if render mode is set to cutoff
}
base.OnGUI(editor, properties); //Render the default GUI in the end
}
//Switch render modes according to the user's choice
void RunRenderModes()
{
RenderMode mode = RenderMode.Opaque;
showAlphaCutoff = false;
if (IsKeywordEnabled("_RENDERING_CUTOUT"))
{
mode = RenderMode.Cutout;
showAlphaCutoff = true;
}
else if (IsKeywordEnabled("_RENDERING_FADE"))
{
mode = RenderMode.Fade;
}
else if (IsKeywordEnabled("_RENDERING_TRANSPARENT"))
{
mode = RenderMode.Transparent;
}
EditorGUI.BeginChangeCheck();
mode = (RenderMode)EditorGUILayout.EnumPopup(
MakeLabel("Render Mode"), mode
);
if (EditorGUI.EndChangeCheck())
{
RecordAction("Render Mode");
SetKeyword("_RENDERING_CUTOUT", mode == RenderMode.Cutout);
SetKeyword("_RENDERING_FADE", mode == RenderMode.Fade);
SetKeyword(
"_RENDERING_TRANSPARENT", mode == RenderMode.Transparent
);
RenderSettings settings = RenderSettings.modes[(int)mode];
foreach (Material m in editor.targets)
{
m.renderQueue = (int)settings.queue;
m.SetOverrideTag("RenderType", settings.renderType);
m.SetInt("_SrcBlend", (int)settings.srcBlend);
m.SetInt("_DstBlend", (int)settings.dstBlend);
m.SetInt("_ZWrite", settings.zWrite ? 1 : 0);
}
}
}
//Manipulates the alpha cutoff value accoring to slider value
void SetAlphaCutoff()
{
MaterialProperty slider = FindProperty("_AlphaCutoff");
EditorGUI.indentLevel += 2;
editor.ShaderProperty(slider, MakeLabel(slider));
EditorGUI.indentLevel -= 2;
}
//Finds material property name
MaterialProperty FindProperty(string name)
{
return FindProperty(name, properties);
}
static GUIContent MakeLabel(string text, string tooltip = null)
{
staticLabel.text = text;
staticLabel.tooltip = tooltip;
return staticLabel;
}
static GUIContent MakeLabel(
MaterialProperty property, string tooltip = null
)
{
staticLabel.text = property.displayName;
staticLabel.tooltip = tooltip;
return staticLabel;
}
void SetKeyword(string keyword, bool state)
{
if (state)
{
foreach (Material m in editor.targets)
{
m.EnableKeyword(keyword);
}
}
else
{
foreach (Material m in editor.targets)
{
m.DisableKeyword(keyword);
}
}
}
bool IsKeywordEnabled(string keyword)
{
return target.IsKeywordEnabled(keyword);
}
void RecordAction(string label)
{
editor.RegisterPropertyChangeUndo(label);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8b8b17bf436260542ab7569c4d34e4b8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: