Commit e3250e40 authored by Tommé Nöll's avatar Tommé Nöll
Browse files

added diffuse lighting capability to corruption shader

parent 9c5f974a
......@@ -7,8 +7,8 @@ Material:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: PlantMaterial
m_Shader: {fileID: 4800000, guid: 1f1ecd67182ff5436bf3ab78f7518b25, type: 3}
m_Name: SpriteDiffuse
m_Shader: {fileID: 10800, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords: ETC1_EXTERNAL_ALPHA
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
......@@ -19,11 +19,11 @@ Material:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
- _AlphaTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _CorruptionMap:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
......@@ -60,22 +60,19 @@ Material:
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- PixelSnap: 0
- _BumpScale: 1
- _ColorStrengthExponent: 5
- _Corruption: -2.45
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _EnableExternalAlpha: 0
- _GlossMapScale: 1
- _Glossiness: 0
- _Glossiness: 0.5
- _GlossyReflections: 1
- _GreenExponent: 5.16
- _Metallic: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _PulsatingSpeed: 1
- _PulsatingStrength: 17.31
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
......@@ -83,10 +80,6 @@ Material:
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _ColorDividers: {r: 1, g: 1.72, b: 1, a: 1}
- _ColorFactors: {r: 9.31, g: -18.34, b: 7.17, a: 1}
- _ColorInFactors: {r: -0.17, g: 1.19, b: -0.24, a: 0}
- _ColorOutFactors: {r: 10, g: -20, b: 9, a: 0}
- _ColorStrengthFactors: {r: -0.18, g: 1.18, b: -0.21, a: 0}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _MainCameraPos: {r: 5.35, g: 1.67, b: -10, a: 0}
- _Flip: {r: 1, g: 1, b: 1, a: 1}
- _RendererColor: {r: 1, g: 1, b: 1, a: 1}
fileFormatVersion: 2
guid: ac1fcd6dcb153b8b3bb2c6ca837296ff
guid: 29e4a79a79b470fd5b3021938034169a
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
......
......@@ -126,6 +126,40 @@ Transform:
type: 3}
m_PrefabInstance: {fileID: 2030130258}
m_PrefabAsset: {fileID: 0}
--- !u!84 &12996696
RenderTexture:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
m_ForcedFallbackFormat: 4
m_DownscaleFallback: 0
serializedVersion: 3
m_Width: 945
m_Height: 539
m_AntiAliasing: 1
m_DepthFormat: 0
m_ColorFormat: 21
m_MipMap: 0
m_GenerateMips: 1
m_SRGB: 0
m_UseDynamicScale: 0
m_BindMS: 0
m_EnableCompatibleFormat: 1
m_TextureSettings:
serializedVersion: 2
m_FilterMode: 1
m_Aniso: 1
m_MipBias: 0
m_WrapU: 1
m_WrapV: 1
m_WrapW: 1
m_Dimension: 2
m_VolumeDepth: 1
--- !u!1001 &35719956
PrefabInstance:
m_ObjectHideFlags: 0
......@@ -2970,6 +3004,11 @@ PrefabInstance:
propertyPath: m_Enabled
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1793944872162975611, guid: a1e0107a2375e1140a669c1da0647f9a,
type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 2100000, guid: 29e4a79a79b470fd5b3021938034169a, type: 2}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: a1e0107a2375e1140a669c1da0647f9a, type: 3}
--- !u!1001 &1206557182
......@@ -3582,7 +3621,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!108 &1419934973
Light:
m_ObjectHideFlags: 0
......@@ -3594,8 +3633,8 @@ Light:
serializedVersion: 9
m_Type: 2
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Intensity: 1
m_Range: 10
m_Intensity: 2.66
m_Range: 46.12
m_SpotAngle: 30
m_InnerSpotAngle: 21.802082
m_CookieSize: 10
......@@ -3651,7 +3690,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1419934972}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 4.469, y: 2.69, z: -0.501}
m_LocalPosition: {x: -2.03, y: -2.64, z: -0.501}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
......@@ -4026,40 +4065,6 @@ Transform:
type: 3}
m_PrefabInstance: {fileID: 1549918673}
m_PrefabAsset: {fileID: 0}
--- !u!84 &1550108567
RenderTexture:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
m_ForcedFallbackFormat: 4
m_DownscaleFallback: 0
serializedVersion: 3
m_Width: 945
m_Height: 539
m_AntiAliasing: 1
m_DepthFormat: 0
m_ColorFormat: 21
m_MipMap: 0
m_GenerateMips: 1
m_SRGB: 0
m_UseDynamicScale: 0
m_BindMS: 0
m_EnableCompatibleFormat: 1
m_TextureSettings:
serializedVersion: 2
m_FilterMode: 1
m_Aniso: 1
m_MipBias: 0
m_WrapU: 1
m_WrapV: 1
m_WrapW: 1
m_Dimension: 2
m_VolumeDepth: 1
--- !u!1001 &1551787235
PrefabInstance:
m_ObjectHideFlags: 0
......@@ -4219,7 +4224,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!4 &1653916939
Transform:
m_ObjectHideFlags: 0
......@@ -4472,6 +4477,11 @@ PrefabInstance:
propertyPath: m_Name
value: CorruptionZone (1)
objectReference: {fileID: 0}
- target: {fileID: 1362442974637441874, guid: 47edb6c4e8357676a9cb004f1655d229,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 146384502658720480, guid: 47edb6c4e8357676a9cb004f1655d229,
type: 3}
propertyPath: m_RootOrder
......@@ -4480,12 +4490,12 @@ PrefabInstance:
- target: {fileID: 146384502658720480, guid: 47edb6c4e8357676a9cb004f1655d229,
type: 3}
propertyPath: m_LocalPosition.x
value: 3.49
value: 12.57
objectReference: {fileID: 0}
- target: {fileID: 146384502658720480, guid: 47edb6c4e8357676a9cb004f1655d229,
type: 3}
propertyPath: m_LocalPosition.y
value: 2.09
value: 7.78
objectReference: {fileID: 0}
- target: {fileID: 146384502658720480, guid: 47edb6c4e8357676a9cb004f1655d229,
type: 3}
......@@ -4913,6 +4923,97 @@ PrefabInstance:
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 7ef06ffc179d97098a6c30d5f8570a4e, type: 3}
--- !u!1 &1845706291
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1845706293}
- component: {fileID: 1845706292}
m_Layer: 0
m_Name: Directional Light (1)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!108 &1845706292
Light:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1845706291}
m_Enabled: 1
serializedVersion: 9
m_Type: 1
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Intensity: 1
m_Range: 10
m_SpotAngle: 30
m_InnerSpotAngle: 21.802082
m_CookieSize: 10
m_Shadows:
m_Type: 0
m_Resolution: -1
m_CustomResolution: -1
m_Strength: 1
m_Bias: 0.05
m_NormalBias: 0.4
m_NearPlane: 0.2
m_CullingMatrixOverride:
e00: 1
e01: 0
e02: 0
e03: 0
e10: 0
e11: 1
e12: 0
e13: 0
e20: 0
e21: 0
e22: 1
e23: 0
e30: 0
e31: 0
e32: 0
e33: 1
m_UseCullingMatrixOverride: 0
m_Cookie: {fileID: 0}
m_DrawHalo: 0
m_Flare: {fileID: 0}
m_RenderMode: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingLayerMask: 1
m_Lightmapping: 4
m_LightShadowCasterMode: 0
m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 1
m_ColorTemperature: 6570
m_UseColorTemperature: 0
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
m_UseBoundingSphereOverride: 0
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!4 &1845706293
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1845706291}
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
m_LocalPosition: {x: 0.38816744, y: 15.33, z: -21.778965}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 11
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1001 &1854361418
PrefabInstance:
m_ObjectHideFlags: 0
......@@ -5740,12 +5841,12 @@ PrefabInstance:
- target: {fileID: 5546039070061430727, guid: 5f19e99694f67a245b4244a6b9f38023,
type: 3}
propertyPath: m_LocalPosition.x
value: 9.71
value: 10.98
objectReference: {fileID: 0}
- target: {fileID: 5546039070061430727, guid: 5f19e99694f67a245b4244a6b9f38023,
type: 3}
propertyPath: m_LocalPosition.y
value: 3.09
value: 1.99
objectReference: {fileID: 0}
- target: {fileID: 5546039070061430727, guid: 5f19e99694f67a245b4244a6b9f38023,
type: 3}
......@@ -5780,7 +5881,7 @@ PrefabInstance:
type: 3}
propertyPath: m_TargetTexture
value:
objectReference: {fileID: 1550108567}
objectReference: {fileID: 12996696}
- target: {fileID: 8811539148413200178, guid: 388a7af523fdebaafad4a5d1ae1a896b,
type: 3}
propertyPath: orthographic size
......@@ -5794,12 +5895,12 @@ PrefabInstance:
- target: {fileID: 8811539149977030266, guid: 388a7af523fdebaafad4a5d1ae1a896b,
type: 3}
propertyPath: m_LocalPosition.x
value: 5.31
value: 6.04
objectReference: {fileID: 0}
- target: {fileID: 8811539149977030266, guid: 388a7af523fdebaafad4a5d1ae1a896b,
type: 3}
propertyPath: m_LocalPosition.y
value: 3.2
value: 2.28
objectReference: {fileID: 0}
- target: {fileID: 8811539149977030266, guid: 388a7af523fdebaafad4a5d1ae1a896b,
type: 3}
......@@ -5906,6 +6007,11 @@ PrefabInstance:
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8811539148413200141, guid: 388a7af523fdebaafad4a5d1ae1a896b,
type: 3}
propertyPath: m_LocalScale.z
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3934326332992677147, guid: 388a7af523fdebaafad4a5d1ae1a896b,
type: 3}
propertyPath: volumeLayer.m_Bits
......
......@@ -37,24 +37,18 @@ Shader "Custom/PlantSpriteShader"
ZWrite Off
Blend One OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex p_SpriteVert
#pragma fragment p_SpriteFrag
#pragma surface p_SpriteSurf Lambert vertex:p_SpriteVert
#pragma target 2.0
#pragma multi_compile_instancing
#pragma multi_compile _ ETC1_EXTERNAL_ALPHA
#pragma multi_compile EDITOR_ON EDITOR_OFF
#include "UnitySprites.cginc"
struct p_v2f
struct Input
{
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
float4 clipPos : SV_POSITION;
float2 screenPos : TEXCOORD1;
UNITY_VERTEX_OUTPUT_STEREO
float2 uv_MainTex;
float2 customScreenPos;
};
#if EDITOR_ON
......@@ -62,33 +56,21 @@ Shader "Custom/PlantSpriteShader"
float _CorruptionCameraScaleFactor;
#endif
p_v2f p_SpriteVert(appdata_t IN)
void p_SpriteVert(inout appdata_full IN, out Input OUT)
{
p_v2f OUT;
UNITY_SETUP_INSTANCE_ID (IN);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
OUT.clipPos = UnityFlipSprite(IN.vertex, _Flip);
OUT.clipPos = UnityObjectToClipPos(OUT.clipPos);
OUT.texcoord = IN.texcoord;
OUT.color = IN.color * _Color * _RendererColor;
UNITY_INITIALIZE_OUTPUT(Input, OUT);
#if EDITOR_ON
const float2 center = (0.5, 0.5);
float4 screenPos = ComputeScreenPos(mul(_ToMainCameraMatrix, IN.vertex));
float4 screenPos = ComputeScreenPos(mul(_ToMainCameraMatrix, mul(unity_ObjectToWorld, IN.vertex)));
screenPos.xy = screenPos.xy / screenPos.w;
screenPos.xy = (screenPos.xy + center * (_CorruptionCameraScaleFactor - 1))/_CorruptionCameraScaleFactor;
OUT.screenPos = screenPos.xy;
OUT.customScreenPos = screenPos.xy;
#else
float4 screenPos = ComputeScreenPos(UnityObjectToClipPos(IN.vertex));
OUT.screenPos = screenPos.xy / screenPos.w;
OUT.customScreenPos = screenPos.xy / screenPos.w;
#endif
//OUT.worldPos = UnityObjectToClipPos(IN.vertex);
return OUT;
}
sampler2D _CorruptionMap;
......@@ -98,118 +80,16 @@ Shader "Custom/PlantSpriteShader"
float _PulsatingSpeed;
float _PulsatingStrength;
fixed4 p_SpriteFrag(p_v2f IN) : SV_Target
void p_SpriteSurf(Input IN, inout SurfaceOutput o)
{
fixed4 color = SampleSpriteTexture (IN.texcoord) * IN.color;
float corruption = tex2D(_CorruptionMap, IN.screenPos) * 3;
float colorstrength = dot(_ColorStrengthFactors, color);
o.Albedo = tex2D (_MainTex, IN.uv_MainTex);
float corruption = tex2D(_CorruptionMap, IN.customScreenPos) * 3;
float colorstrength = dot(_ColorStrengthFactors, o.Albedo);
float colorshift = max(pow(colorstrength, _ColorStrengthExponent) * corruption * (0.5 + _PulsatingStrength / 50 * (sin(_Time[1] * _PulsatingSpeed) / 2)), 0);
color += colorshift * _ColorOutFactors;
color.rgb *= color.a;
//color.rgb = UnityObjectToClipPos(IN.localPos.xyz);
return color;
o.Albedo += colorshift * _ColorOutFactors;
//o.Albedo.rg = (IN.customScreenPos); o.Albedo.b = 0;
//o.Albedo.rgb *= o.Albedo.a;
}
#define UnitySprites
#ifndef UnitySprites
// UnitySprites.cginc, for reference
#ifndef UNITY_SPRITES_INCLUDED
#define UNITY_SPRITES_INCLUDED
#include "UnityCG.cginc"
#ifdef UNITY_INSTANCING_ENABLED
UNITY_INSTANCING_BUFFER_START(PerDrawSprite)
// SpriteRenderer.Color while Non-Batched/Instanced.
UNITY_DEFINE_INSTANCED_PROP(fixed4, unity_SpriteRendererColorArray)
// this could be smaller but that's how bit each entry is regardless of type
UNITY_DEFINE_INSTANCED_PROP(fixed2, unity_SpriteFlipArray)
UNITY_INSTANCING_BUFFER_END(PerDrawSprite)
#define _RendererColor UNITY_ACCESS_INSTANCED_PROP(PerDrawSprite, unity_SpriteRendererColorArray)
#define _Flip UNITY_ACCESS_INSTANCED_PROP(PerDrawSprite, unity_SpriteFlipArray)
#endif // instancing
CBUFFER_START(UnityPerDrawSprite)
#ifndef UNITY_INSTANCING_ENABLED
fixed4 _RendererColor;
fixed2 _Flip;
#endif
float _EnableExternalAlpha;
CBUFFER_END
// Material Color.
fixed4 _Color;
struct appdata_t
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_OUTPUT_STEREO
};
inline float4 UnityFlipSprite(in float3 pos, in fixed2 flip)
{
return float4(pos.xy * flip, pos.z, 1.0);
}
v2f SpriteVert(appdata_t IN)
{
v2f OUT;
UNITY_SETUP_INSTANCE_ID (IN);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
OUT.vertex = UnityFlipSprite(IN.vertex, _Flip);
OUT.vertex = UnityObjectToClipPos(OUT.vertex);
OUT.texcoord = IN.texcoord;
OUT.color = IN.color * _Color * _RendererColor;
#ifdef PIXELSNAP_ON
OUT.vertex = UnityPixelSnap (OUT.vertex);
#endif
return OUT;
}
sampler2D _MainTex;
sampler2D _AlphaTex;
fixed4 SampleSpriteTexture (float2 uv)
{
fixed4 color = tex2D (_MainTex, uv);
#if ETC1_EXTERNAL_ALPHA
fixed4 alpha = tex2D (_AlphaTex, uv);
color.a = lerp (color.a, alpha.r, _EnableExternalAlpha);
#endif
return color;
}
fixed4 SpriteFrag(v2f IN) : SV_Target
{
fixed4 c = SampleSpriteTexture (IN.texcoord) * IN.color;
c.rgb *= c.a;
return c;
}
#endif // UNITY_SPRITES_INCLUDED
#endif // UNITY_SPRITES
ENDCG
}
}
}
}
\ No newline at end of file
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "Custom/PlantSurfaceShader"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
_ColorStrengthFactors("ColorStrengthFactors", Vector) = (0, 1, 0, 0)
_ColorStrengthExponent("ColorStrengthExponent", Float) = 5.0
_ColorOutFactors("ColorChangeFactors", Vector) = (10, -20, 9, 0)
_PulsatingSpeed("PulsatingSpeed", Float) = 1.3
_PulsatingStrength("PulsatingStrength", Float) = 0.8
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows
#pragma multi_compile EDITOR_ON EDITOR_OFF
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0