├── .gitignore ├── Assets ├── IndieSoftShadows.meta ├── IndieSoftShadows │ ├── Materials.meta │ ├── Materials │ │ ├── Default Diffuse Bumped.mat │ │ ├── Default Diffuse Bumped.mat.meta │ │ ├── Indie Diffuse Bumped SoftShadow.mat │ │ ├── Indie Diffuse Bumped SoftShadow.mat.meta │ │ ├── Sample Particle Material.mat │ │ └── Sample Particle Material.mat.meta │ ├── Scenes.meta │ ├── Scenes │ │ ├── scene_indiesoftshadow1.unity │ │ └── scene_indiesoftshadow1.unity.meta │ ├── Scripts.meta │ └── Scripts │ │ ├── LightRotator.cs │ │ └── LightRotator.cs.meta ├── Shaders.meta ├── Shaders │ ├── !note_Autolight must be in the same directory as the shader.txt │ ├── !note_Autolight must be in the same directory as the shader.txt.meta │ ├── AutoLight.cginc │ ├── AutoLight.cginc.meta │ ├── Diffuse_SoftShadow1.shader │ ├── Diffuse_SoftShadow1.shader.meta │ ├── Normal-Diffuse_soft.shader │ └── Normal-Diffuse_soft.shader.meta ├── Textures.meta └── Textures │ ├── Sample texture from CGTextures - WoodPlanksClean0071.URL │ ├── Sample texture from CGTextures - WoodPlanksClean0071.URL.meta │ ├── WoodPlanksClean0063_2_N.jpg │ ├── WoodPlanksClean0063_2_N.jpg.meta │ ├── WoodPlanksClean0063_2_S.jpg │ └── WoodPlanksClean0063_2_S.jpg.meta ├── LICENSE ├── Library ├── AnnotationManager ├── AssetVersioning.db ├── BuildPlayer.prefs ├── BuildSettings.asset ├── EditorUserSettings.asset ├── MonoManager.asset ├── ProjectSettings.asset └── ShaderCache.db ├── ProjectSettings ├── AudioManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── InputManager.asset ├── NavMeshLayers.asset ├── NetworkManager.asset ├── Physics2DSettings.asset ├── ProjectSettings.asset ├── QualitySettings.asset ├── TagManager.asset └── TimeManager.asset └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Unity3D .gitignore file. 2 | # Store this file at the root of your local repository. 3 | .DS_Store 4 | Library/AssetImportState 5 | Library/AssetServerCacheV3 6 | Library/FailedAssetImports.txt 7 | Library/ScriptAssemblies 8 | Library/ScriptMapper 9 | Library/assetDatabase3 10 | Library/cache 11 | Library/ShaderCache 12 | Library/expandedItems 13 | Library/metadata 14 | Library/previews 15 | Library/guidmapper 16 | /Temp 17 | /builds 18 | *.csproj 19 | *.pidb 20 | *.sln 21 | *.userprefs 22 | *.unityproj 23 | InspectorExpandedItems.asset 24 | EditorUserBuildSettings.asset 25 | Library/CurrentMaximizeLayout.dwlt 26 | Library/CurrentLayout.dwlt 27 | Library/ShaderCache.db -------------------------------------------------------------------------------- /Assets/IndieSoftShadows.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ccdc6c1104e22ec4d8a5cda6e4fd4696 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/IndieSoftShadows/Materials.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 67470bbe6222d3b4d9b32183a3d9d6dd 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/IndieSoftShadows/Materials/Default Diffuse Bumped.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unitycoder/IndieSoftShadow/41b873d926916ba7a94b6ef1b0b2406698607ab1/Assets/IndieSoftShadows/Materials/Default Diffuse Bumped.mat -------------------------------------------------------------------------------- /Assets/IndieSoftShadows/Materials/Default Diffuse Bumped.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 75b734cc911edd544a7dddd8a4e8bd18 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/IndieSoftShadows/Materials/Indie Diffuse Bumped SoftShadow.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unitycoder/IndieSoftShadow/41b873d926916ba7a94b6ef1b0b2406698607ab1/Assets/IndieSoftShadows/Materials/Indie Diffuse Bumped SoftShadow.mat -------------------------------------------------------------------------------- /Assets/IndieSoftShadows/Materials/Indie Diffuse Bumped SoftShadow.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 99284a6884a59614c9dc664133af7b8b 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/IndieSoftShadows/Materials/Sample Particle Material.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unitycoder/IndieSoftShadow/41b873d926916ba7a94b6ef1b0b2406698607ab1/Assets/IndieSoftShadows/Materials/Sample Particle Material.mat -------------------------------------------------------------------------------- /Assets/IndieSoftShadows/Materials/Sample Particle Material.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 91987940d07189b42941e4789b76c73d 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/IndieSoftShadows/Scenes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3c57c76658e4ed942b0f5969a02c116f 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/IndieSoftShadows/Scenes/scene_indiesoftshadow1.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unitycoder/IndieSoftShadow/41b873d926916ba7a94b6ef1b0b2406698607ab1/Assets/IndieSoftShadows/Scenes/scene_indiesoftshadow1.unity -------------------------------------------------------------------------------- /Assets/IndieSoftShadows/Scenes/scene_indiesoftshadow1.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 86e450b2b11003a44a722d9bcf7aedc8 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/IndieSoftShadows/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 155255ff1e511cd41a8771d1fdfd7e8c 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/IndieSoftShadows/Scripts/LightRotator.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | 5 | public class LightRotator : MonoBehaviour { 6 | 7 | 8 | 9 | void Update () { 10 | 11 | transform.eulerAngles += new Vector3(0,10*Time.deltaTime,0); 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Assets/IndieSoftShadows/Scripts/LightRotator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fd14b34234ee0de4b81807bbea8ecfc9 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Assets/Shaders.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6a3e7ae734130b54ebb59e006b0487a9 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Shaders/!note_Autolight must be in the same directory as the shader.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unitycoder/IndieSoftShadow/41b873d926916ba7a94b6ef1b0b2406698607ab1/Assets/Shaders/!note_Autolight must be in the same directory as the shader.txt -------------------------------------------------------------------------------- /Assets/Shaders/!note_Autolight must be in the same directory as the shader.txt.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 90a9d105579907546b8a5ff5ac0f590f 3 | TextScriptImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Shaders/AutoLight.cginc: -------------------------------------------------------------------------------- 1 | #ifndef AUTOLIGHT_INCLUDED 2 | #define AUTOLIGHT_INCLUDED 3 | 4 | #include "HLSLSupport.cginc" 5 | 6 | // ------------ Shadow helpers -------- 7 | 8 | 9 | // ---- Screen space shadows 10 | #if defined (SHADOWS_SCREEN) 11 | 12 | uniform float4 _ShadowOffsets[4]; 13 | 14 | #if defined(SHADOWS_NATIVE) 15 | UNITY_DECLARE_SHADOWMAP(_ShadowMapTexture); 16 | #else 17 | uniform sampler2D _ShadowMapTexture; 18 | #endif 19 | 20 | #define SHADOW_COORDS(idx1) float4 _ShadowCoord : TEXCOORD##idx1; 21 | 22 | #if (defined(SHADER_API_GLES) || defined(SHADER_API_GLES3)) && defined(SHADER_API_MOBILE) 23 | #define TRANSFER_SHADOW(a) a._ShadowCoord = mul( unity_World2Shadow[0], mul( _Object2World, v.vertex ) ); 24 | 25 | inline fixed unitySampleShadow (float4 shadowCoord) 26 | { 27 | //#if defined(SHADOWS_NATIVE) 28 | 29 | fixed shadow = UNITY_SAMPLE_SHADOW(_ShadowMapTexture, shadowCoord.xyz); 30 | shadow = _LightShadowData.r + shadow * (1-_LightShadowData.r); 31 | return shadow; 32 | 33 | //#else 34 | 35 | //float dist = tex2Dproj( _ShadowMapTexture, UNITY_PROJ_COORD(shadowCoord) ).x; 36 | 37 | // tegra is confused if we use _LightShadowData.x directly 38 | // with "ambiguous overloaded function reference max(mediump float, float)" 39 | // half lightShadowDataX = _LightShadowData.x; 40 | // return 1; //max(dist > (shadowCoord.z/shadowCoord.w), lightShadowDataX); 41 | 42 | // #endif 43 | } 44 | 45 | #else // !((defined(SHADER_API_GLES) || defined(SHADER_API_GLES3)) && defined(SHADER_API_MOBILE)) 46 | 47 | #define TRANSFER_SHADOW(a) a._ShadowCoord = ComputeScreenPos(a.pos); 48 | 49 | 50 | 51 | // INDIE DIRECTIONAL SOFT SHADOWS IS HAPPENING RIGHT HERE :) 52 | //inline fixed unitySampleShadow (float4 shadowCoord) 53 | inline half unitySampleShadow (float4 shadowCoord) 54 | { 55 | 56 | // basic blur effect for shadow v1.0 57 | 58 | float blurDist = 0.02; // how far we take neighbour pixel value 59 | 60 | float mainStrength = 0.2; 61 | float subStrength = 0.1; // mainStrength+(subStrength*samples) should add up to 1 62 | 63 | 64 | // fixed shadow = tex2Dproj( _ShadowMapTexture, UNITY_PROJ_COORD(shadowCoord)).r*mainStrength; // middle 65 | half shadow = tex2Dproj( _ShadowMapTexture, UNITY_PROJ_COORD(shadowCoord)).r*mainStrength; // middle 66 | 67 | 68 | // take neighbour samples 69 | shadow += tex2Dproj( _ShadowMapTexture, UNITY_PROJ_COORD( shadowCoord+float4(blurDist ,0,0,0) )).r*subStrength; // right 70 | shadow += tex2Dproj( _ShadowMapTexture, UNITY_PROJ_COORD( shadowCoord+float4(-blurDist,0,0,0) )).r*subStrength; // left 71 | shadow += tex2Dproj( _ShadowMapTexture, UNITY_PROJ_COORD( shadowCoord+float4(0 ,blurDist,0,0) )).r*subStrength; // up 72 | shadow += tex2Dproj( _ShadowMapTexture, UNITY_PROJ_COORD( shadowCoord+float4(0 ,-blurDist,0,0) )).r*subStrength; // down 73 | 74 | shadow += tex2Dproj( _ShadowMapTexture, UNITY_PROJ_COORD( shadowCoord+float4(blurDist ,blurDist,0,0) )).r*subStrength; // top right 75 | shadow += tex2Dproj( _ShadowMapTexture, UNITY_PROJ_COORD( shadowCoord+float4(-blurDist ,blurDist,0,0) )).r*subStrength; // top left 76 | shadow += tex2Dproj( _ShadowMapTexture, UNITY_PROJ_COORD( shadowCoord+float4(-blurDist ,-blurDist,0,0) )).r*subStrength; // bottom left 77 | shadow += tex2Dproj( _ShadowMapTexture, UNITY_PROJ_COORD( shadowCoord+float4(blurDist ,-blurDist,0,0) )).r*subStrength; // bottom right 78 | 79 | 80 | /* 81 | // test another way..these ones start to break if look too far.. 82 | float3 coord = shadowCoord.xyz / shadowCoord.w; 83 | //shadow = UNITY_SAMPLE_DEPTH (tex2D( _ShadowMapTexture, coord+float2(0,0) )); 84 | shadow = UNITY_SAMPLE_DEPTH (tex2D( _ShadowMapTexture, coord+float3(blurDist,0,0) )); 85 | shadow += UNITY_SAMPLE_DEPTH (tex2D( _ShadowMapTexture, coord+float3(-blurDist,0,0) )); 86 | shadow += UNITY_SAMPLE_DEPTH (tex2D( _ShadowMapTexture, coord+float3(0,blurDist,0) )); 87 | shadow += UNITY_SAMPLE_DEPTH (tex2D( _ShadowMapTexture, coord+float3(0,-blurDist,0) )); 88 | 89 | shadow += UNITY_SAMPLE_DEPTH (tex2D( _ShadowMapTexture, coord+float3(blurDist,blurDist,0) )); 90 | shadow += UNITY_SAMPLE_DEPTH (tex2D( _ShadowMapTexture, coord+float3(blurDist,-blurDist,0) )); 91 | shadow += UNITY_SAMPLE_DEPTH (tex2D( _ShadowMapTexture, coord+float3(-blurDist,blurDist,0) )); 92 | shadow += UNITY_SAMPLE_DEPTH (tex2D( _ShadowMapTexture, coord+float3(-blurDist,-blurDist,0) )); 93 | 94 | shadow *= 0.125f; 95 | */ 96 | 97 | 98 | /* 99 | // test using unity soft shadow: 100 | float3 coord = shadowCoord.xyz / shadowCoord.w; 101 | float4 shadowVals; 102 | shadowVals.x = UNITY_SAMPLE_DEPTH (tex2D( _ShadowMapTexture, coord +float2(0,s) )); 103 | shadowVals.y = UNITY_SAMPLE_DEPTH (tex2D( _ShadowMapTexture, coord +float2(s,0) )); 104 | shadowVals.z = UNITY_SAMPLE_DEPTH (tex2D( _ShadowMapTexture, coord +float2(-s,0) )); 105 | shadowVals.w = UNITY_SAMPLE_DEPTH (tex2D( _ShadowMapTexture, coord +float2(0,-s) )); 106 | half4 shadows = (shadowVals < coord.zzzz) ? _LightShadowData.rrrr : 1.0f; 107 | // average-4 PCF 108 | half shadow = dot (shadows, 0.25f); 109 | */ 110 | 111 | 112 | 113 | // fixed shadow = UNITY_SAMPLE_SHADOW(_ShadowMapTexture, shadowCoord.xyz); 114 | // shadow = _LightShadowData.r + shadow * (1-_LightShadowData.r); 115 | 116 | return shadow; 117 | } 118 | 119 | #endif 120 | 121 | #define SHADOW_ATTENUATION(a) unitySampleShadow(a._ShadowCoord) 122 | 123 | #endif 124 | 125 | 126 | // ---- Depth map shadows 127 | 128 | #if defined (SHADOWS_DEPTH) && defined (SPOT) 129 | 130 | #if !defined(SHADOWMAPSAMPLER_DEFINED) 131 | UNITY_DECLARE_SHADOWMAP(_ShadowMapTexture); 132 | #endif 133 | #if defined (SHADOWS_SOFT) 134 | uniform float4 _ShadowOffsets[4]; 135 | #endif 136 | 137 | inline fixed unitySampleShadow (float4 shadowCoord) 138 | { 139 | #if defined (SHADOWS_SOFT) 140 | 141 | // 4-tap shadows 142 | 143 | float3 coord = shadowCoord.xyz / shadowCoord.w; 144 | #if defined (SHADOWS_NATIVE) 145 | half4 shadows; 146 | shadows.x = UNITY_SAMPLE_SHADOW(_ShadowMapTexture, coord + _ShadowOffsets[0]); 147 | shadows.y = UNITY_SAMPLE_SHADOW(_ShadowMapTexture, coord + _ShadowOffsets[1]); 148 | shadows.z = UNITY_SAMPLE_SHADOW(_ShadowMapTexture, coord + _ShadowOffsets[2]); 149 | shadows.w = UNITY_SAMPLE_SHADOW(_ShadowMapTexture, coord + _ShadowOffsets[3]); 150 | shadows = _LightShadowData.rrrr + shadows * (1-_LightShadowData.rrrr); 151 | #else 152 | float4 shadowVals; 153 | shadowVals.x = UNITY_SAMPLE_DEPTH (tex2D( _ShadowMapTexture, coord + _ShadowOffsets[0].xy )); 154 | shadowVals.y = UNITY_SAMPLE_DEPTH (tex2D( _ShadowMapTexture, coord + _ShadowOffsets[1].xy )); 155 | shadowVals.z = UNITY_SAMPLE_DEPTH (tex2D( _ShadowMapTexture, coord + _ShadowOffsets[2].xy )); 156 | shadowVals.w = UNITY_SAMPLE_DEPTH (tex2D( _ShadowMapTexture, coord + _ShadowOffsets[3].xy )); 157 | half4 shadows = (shadowVals < coord.zzzz) ? _LightShadowData.rrrr : 1.0f; 158 | #endif 159 | 160 | // average-4 PCF 161 | half shadow = dot (shadows, 0.25f); 162 | 163 | #else 164 | 165 | // 1-tap shadows 166 | 167 | #if defined (SHADOWS_NATIVE) 168 | half shadow = UNITY_SAMPLE_SHADOW_PROJ(_ShadowMapTexture, shadowCoord); 169 | shadow = _LightShadowData.r + shadow * (1-_LightShadowData.r); 170 | #else 171 | half shadow = UNITY_SAMPLE_DEPTH(tex2Dproj (_ShadowMapTexture, UNITY_PROJ_COORD(shadowCoord))) < (shadowCoord.z / shadowCoord.w) ? _LightShadowData.r : 1.0; 172 | #endif 173 | 174 | #endif 175 | 176 | return shadow; 177 | } 178 | #define SHADOW_COORDS(idx1) float4 _ShadowCoord : TEXCOORD##idx1; 179 | #define TRANSFER_SHADOW(a) a._ShadowCoord = mul (unity_World2Shadow[0], mul(_Object2World,v.vertex)); 180 | #define SHADOW_ATTENUATION(a) unitySampleShadow(a._ShadowCoord) 181 | 182 | #endif 183 | 184 | 185 | // ---- Point light shadows 186 | 187 | #if defined (SHADOWS_CUBE) 188 | 189 | uniform samplerCUBE _ShadowMapTexture; 190 | inline float SampleCubeDistance (float3 vec) 191 | { 192 | float4 packDist = texCUBE (_ShadowMapTexture, vec); 193 | return DecodeFloatRGBA( packDist ); 194 | } 195 | inline float unityCubeShadow (float3 vec) 196 | { 197 | float mydist = length(vec) * _LightPositionRange.w; 198 | mydist *= 0.97; // bias 199 | 200 | #if defined (SHADOWS_SOFT) 201 | float z = 1.0/128.0; 202 | float4 shadowVals; 203 | shadowVals.x = SampleCubeDistance (vec+float3( z, z, z)); 204 | shadowVals.y = SampleCubeDistance (vec+float3(-z,-z, z)); 205 | shadowVals.z = SampleCubeDistance (vec+float3(-z, z,-z)); 206 | shadowVals.w = SampleCubeDistance (vec+float3( z,-z,-z)); 207 | half4 shadows = (shadowVals < mydist.xxxx) ? _LightShadowData.rrrr : 1.0f; 208 | return dot(shadows,0.25); 209 | #else 210 | float dist = SampleCubeDistance (vec); 211 | return dist < mydist ? _LightShadowData.r : 1.0; 212 | #endif 213 | } 214 | #define SHADOW_COORDS(idx1) float3 _ShadowCoord : TEXCOORD##idx1; 215 | #define TRANSFER_SHADOW(a) a._ShadowCoord = mul(_Object2World, v.vertex).xyz - _LightPositionRange.xyz; 216 | #define SHADOW_ATTENUATION(a) unityCubeShadow(a._ShadowCoord) 217 | 218 | #endif 219 | 220 | 221 | 222 | // ---- Shadows off 223 | #if !defined (SHADOWS_SCREEN) && !defined (SHADOWS_DEPTH) && !defined (SHADOWS_CUBE) 224 | 225 | #define SHADOW_COORDS(idx1) 226 | #define TRANSFER_SHADOW(a) 227 | #define SHADOW_ATTENUATION(a) 1.0 228 | 229 | #endif 230 | 231 | 232 | 233 | // ------------ Light helpers -------- 234 | 235 | #ifdef POINT 236 | #define LIGHTING_COORDS(idx1,idx2) float3 _LightCoord : TEXCOORD##idx1; SHADOW_COORDS(idx2) 237 | uniform sampler2D _LightTexture0; 238 | uniform float4x4 _LightMatrix0; 239 | #define TRANSFER_VERTEX_TO_FRAGMENT(a) a._LightCoord = mul(_LightMatrix0, mul(_Object2World, v.vertex)).xyz; TRANSFER_SHADOW(a) 240 | #define LIGHT_ATTENUATION(a) (tex2D(_LightTexture0, dot(a._LightCoord,a._LightCoord).rr).UNITY_ATTEN_CHANNEL * SHADOW_ATTENUATION(a)) 241 | #endif 242 | 243 | #ifdef SPOT 244 | #define LIGHTING_COORDS(idx1,idx2) float4 _LightCoord : TEXCOORD##idx1; SHADOW_COORDS(idx2) 245 | uniform sampler2D _LightTexture0; 246 | uniform float4x4 _LightMatrix0; 247 | uniform sampler2D _LightTextureB0; 248 | #define TRANSFER_VERTEX_TO_FRAGMENT(a) a._LightCoord = mul(_LightMatrix0, mul(_Object2World, v.vertex)); TRANSFER_SHADOW(a) 249 | inline fixed UnitySpotCookie(float4 LightCoord) 250 | { 251 | return tex2D(_LightTexture0, LightCoord.xy / LightCoord.w + 0.5).w; 252 | } 253 | inline fixed UnitySpotAttenuate(float3 LightCoord) 254 | { 255 | return tex2D(_LightTextureB0, dot(LightCoord, LightCoord).xx).UNITY_ATTEN_CHANNEL; 256 | } 257 | #define LIGHT_ATTENUATION(a) ( (a._LightCoord.z > 0) * UnitySpotCookie(a._LightCoord) * UnitySpotAttenuate(a._LightCoord.xyz) * SHADOW_ATTENUATION(a) ) 258 | #endif 259 | 260 | 261 | #ifdef DIRECTIONAL 262 | #define LIGHTING_COORDS(idx1,idx2) SHADOW_COORDS(idx1) 263 | #define TRANSFER_VERTEX_TO_FRAGMENT(a) TRANSFER_SHADOW(a) 264 | #define LIGHT_ATTENUATION(a) SHADOW_ATTENUATION(a) 265 | #endif 266 | 267 | 268 | #ifdef POINT_COOKIE 269 | #define LIGHTING_COORDS(idx1,idx2) float3 _LightCoord : TEXCOORD##idx1; SHADOW_COORDS(idx2) 270 | uniform samplerCUBE _LightTexture0; 271 | uniform float4x4 _LightMatrix0; 272 | uniform sampler2D _LightTextureB0; 273 | #define TRANSFER_VERTEX_TO_FRAGMENT(a) a._LightCoord = mul(_LightMatrix0, mul(_Object2World, v.vertex)).xyz; TRANSFER_SHADOW(a) 274 | #define LIGHT_ATTENUATION(a) (tex2D(_LightTextureB0, dot(a._LightCoord,a._LightCoord).rr).UNITY_ATTEN_CHANNEL * texCUBE(_LightTexture0, a._LightCoord).w * SHADOW_ATTENUATION(a)) 275 | #endif 276 | 277 | #ifdef DIRECTIONAL_COOKIE 278 | #define LIGHTING_COORDS(idx1,idx2) float2 _LightCoord : TEXCOORD##idx1; SHADOW_COORDS(idx2) 279 | uniform sampler2D _LightTexture0; 280 | uniform float4x4 _LightMatrix0; 281 | #define TRANSFER_VERTEX_TO_FRAGMENT(a) a._LightCoord = mul(_LightMatrix0, mul(_Object2World, v.vertex)).xy; TRANSFER_SHADOW(a) 282 | #define LIGHT_ATTENUATION(a) (tex2D(_LightTexture0, a._LightCoord).w * SHADOW_ATTENUATION(a)) 283 | #endif 284 | 285 | 286 | #endif 287 | -------------------------------------------------------------------------------- /Assets/Shaders/AutoLight.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d709733ae4ba6344580a6fdcfb8c3710 3 | ShaderImporter: 4 | defaultTextures: [] 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Shaders/Diffuse_SoftShadow1.shader: -------------------------------------------------------------------------------- 1 | Shader "Indie/Diffuse_SoftShadow1" { 2 | Properties { 3 | _MainTex ("Base (RGB)", 2D) = "white" {} 4 | } 5 | SubShader { 6 | Tags { "RenderType"="Opaque" } 7 | //Tags {"LightMode" = "ForwardBase"} 8 | LOD 200 9 | 10 | CGPROGRAM 11 | #pragma surface surf Lambert 12 | //#include "cgincludes/UnityCG2.cginc" 13 | // #include "AutoLight2.cginc" 14 | //#pragma multi_compile_fwdadd_fullshadows 15 | 16 | sampler2D _MainTex; 17 | 18 | 19 | struct Input { 20 | float2 uv_MainTex; 21 | }; 22 | 23 | void surf (Input IN, inout SurfaceOutput o) { 24 | half4 c = tex2D (_MainTex, IN.uv_MainTex); 25 | //half c2 = tex2D (_ShadowMapTexture, IN.uv_MainTex).r; 26 | //fixed shadow = tex2Dproj( _ShadowMapTexture, UNITY_PROJ_COORD(IN.uv_MainTex) ).r; 27 | o.Albedo = c.rgb; 28 | o.Alpha = c.a; 29 | } 30 | ENDCG 31 | } 32 | FallBack "Diffuse" 33 | } 34 | -------------------------------------------------------------------------------- /Assets/Shaders/Diffuse_SoftShadow1.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dc9c4d25ab2fe564d924138270124c1d 3 | ShaderImporter: 4 | defaultTextures: [] 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Shaders/Normal-Diffuse_soft.shader: -------------------------------------------------------------------------------- 1 | Shader "Indie/Bumped Diffuse SoftShadow1" { 2 | Properties { 3 | _Color ("Main Color", Color) = (1,1,1,1) 4 | _MainTex ("Base (RGB)", 2D) = "white" {} 5 | _BumpMap ("Normalmap", 2D) = "bump" {} 6 | } 7 | 8 | SubShader { 9 | Tags { "RenderType"="Opaque" } 10 | LOD 300 11 | 12 | CGPROGRAM 13 | #pragma surface surf Lambert 14 | //#include "cgincludes/UnityCG2.cginc" 15 | //#pragma target 3.0 // might need this on publish 16 | 17 | sampler2D _MainTex; 18 | sampler2D _BumpMap; 19 | fixed4 _Color; 20 | 21 | struct Input { 22 | float2 uv_MainTex; 23 | float2 uv_BumpMap; 24 | }; 25 | 26 | void surf (Input IN, inout SurfaceOutput o) { 27 | fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color; 28 | o.Albedo = c.rgb; 29 | o.Alpha = c.a; 30 | o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap)); 31 | } 32 | ENDCG 33 | } 34 | 35 | FallBack "Diffuse" 36 | } 37 | -------------------------------------------------------------------------------- /Assets/Shaders/Normal-Diffuse_soft.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 934442a247a77ff44b79bcfdc69305f6 3 | ShaderImporter: 4 | defaultTextures: [] 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Textures.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cfb237304dd2205488bf05a77b061d9b 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Assets/Textures/Sample texture from CGTextures - WoodPlanksClean0071.URL: -------------------------------------------------------------------------------- 1 | [InternetShortcut] 2 | URL=http://cgtextures.com/texview.php?id=46358 3 | IDList= 4 | HotKey=0 5 | IconFile=C:\Users\root\AppData\Local\Mozilla\Firefox\Profiles\prsojl5o.default\shortcutCache\cMsHFGlvOpPK9__pwkmYIQ==.ico 6 | IconIndex=0 7 | -------------------------------------------------------------------------------- /Assets/Textures/Sample texture from CGTextures - WoodPlanksClean0071.URL.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 199611ffc436d944ca286c3c6b5e7954 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Assets/Textures/WoodPlanksClean0063_2_N.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unitycoder/IndieSoftShadow/41b873d926916ba7a94b6ef1b0b2406698607ab1/Assets/Textures/WoodPlanksClean0063_2_N.jpg -------------------------------------------------------------------------------- /Assets/Textures/WoodPlanksClean0063_2_N.jpg.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5848b3550e6396e4487519c8237f7e0d 3 | TextureImporter: 4 | serializedVersion: 2 5 | mipmaps: 6 | mipMapMode: 0 7 | enableMipMap: 1 8 | linearTexture: 1 9 | correctGamma: 0 10 | fadeOut: 0 11 | borderMipMap: 0 12 | mipMapFadeDistanceStart: 1 13 | mipMapFadeDistanceEnd: 3 14 | bumpmap: 15 | convertToNormalMap: 1 16 | externalNormalMap: 1 17 | heightScale: .0500000007 18 | normalMapFilter: 1 19 | isReadable: 0 20 | grayScaleToAlpha: 0 21 | generateCubemap: 0 22 | seamlessCubemap: 0 23 | textureFormat: -1 24 | maxTextureSize: 1024 25 | textureSettings: 26 | filterMode: -1 27 | aniso: -1 28 | mipBias: -1 29 | wrapMode: -1 30 | nPOTScale: 1 31 | lightmap: 0 32 | compressionQuality: 50 33 | spriteMode: 0 34 | spriteExtrude: 1 35 | spriteMeshType: 1 36 | alignment: 0 37 | spritePivot: {x: .5, y: .5} 38 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 39 | spritePixelsToUnits: 100 40 | alphaIsTransparency: 0 41 | textureType: 1 42 | buildTargetSettings: [] 43 | spriteSheet: 44 | sprites: [] 45 | spritePackingTag: 46 | userData: 47 | -------------------------------------------------------------------------------- /Assets/Textures/WoodPlanksClean0063_2_S.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unitycoder/IndieSoftShadow/41b873d926916ba7a94b6ef1b0b2406698607ab1/Assets/Textures/WoodPlanksClean0063_2_S.jpg -------------------------------------------------------------------------------- /Assets/Textures/WoodPlanksClean0063_2_S.jpg.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 46eb376ad4052b341a6fd025f6085cc0 3 | TextureImporter: 4 | serializedVersion: 2 5 | mipmaps: 6 | mipMapMode: 0 7 | enableMipMap: 1 8 | linearTexture: 0 9 | correctGamma: 0 10 | fadeOut: 0 11 | borderMipMap: 0 12 | mipMapFadeDistanceStart: 1 13 | mipMapFadeDistanceEnd: 3 14 | bumpmap: 15 | convertToNormalMap: 0 16 | externalNormalMap: 0 17 | heightScale: .25 18 | normalMapFilter: 0 19 | isReadable: 0 20 | grayScaleToAlpha: 0 21 | generateCubemap: 0 22 | seamlessCubemap: 0 23 | textureFormat: -1 24 | maxTextureSize: 1024 25 | textureSettings: 26 | filterMode: -1 27 | aniso: -1 28 | mipBias: -1 29 | wrapMode: -1 30 | nPOTScale: 1 31 | lightmap: 0 32 | compressionQuality: 50 33 | spriteMode: 0 34 | spriteExtrude: 1 35 | spriteMeshType: 1 36 | alignment: 0 37 | spritePivot: {x: .5, y: .5} 38 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 39 | spritePixelsToUnits: 100 40 | alphaIsTransparency: 0 41 | textureType: 0 42 | buildTargetSettings: [] 43 | spriteSheet: 44 | sprites: [] 45 | spritePackingTag: 46 | userData: 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 unitycoder 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /Library/AnnotationManager: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unitycoder/IndieSoftShadow/41b873d926916ba7a94b6ef1b0b2406698607ab1/Library/AnnotationManager -------------------------------------------------------------------------------- /Library/AssetVersioning.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unitycoder/IndieSoftShadow/41b873d926916ba7a94b6ef1b0b2406698607ab1/Library/AssetVersioning.db -------------------------------------------------------------------------------- /Library/BuildPlayer.prefs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unitycoder/IndieSoftShadow/41b873d926916ba7a94b6ef1b0b2406698607ab1/Library/BuildPlayer.prefs -------------------------------------------------------------------------------- /Library/BuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unitycoder/IndieSoftShadow/41b873d926916ba7a94b6ef1b0b2406698607ab1/Library/BuildSettings.asset -------------------------------------------------------------------------------- /Library/EditorUserSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unitycoder/IndieSoftShadow/41b873d926916ba7a94b6ef1b0b2406698607ab1/Library/EditorUserSettings.asset -------------------------------------------------------------------------------- /Library/MonoManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unitycoder/IndieSoftShadow/41b873d926916ba7a94b6ef1b0b2406698607ab1/Library/MonoManager.asset -------------------------------------------------------------------------------- /Library/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unitycoder/IndieSoftShadow/41b873d926916ba7a94b6ef1b0b2406698607ab1/Library/ProjectSettings.asset -------------------------------------------------------------------------------- /Library/ShaderCache.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unitycoder/IndieSoftShadow/41b873d926916ba7a94b6ef1b0b2406698607ab1/Library/ShaderCache.db -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unitycoder/IndieSoftShadow/41b873d926916ba7a94b6ef1b0b2406698607ab1/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unitycoder/IndieSoftShadow/41b873d926916ba7a94b6ef1b0b2406698607ab1/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unitycoder/IndieSoftShadow/41b873d926916ba7a94b6ef1b0b2406698607ab1/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unitycoder/IndieSoftShadow/41b873d926916ba7a94b6ef1b0b2406698607ab1/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unitycoder/IndieSoftShadow/41b873d926916ba7a94b6ef1b0b2406698607ab1/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unitycoder/IndieSoftShadow/41b873d926916ba7a94b6ef1b0b2406698607ab1/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshLayers.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unitycoder/IndieSoftShadow/41b873d926916ba7a94b6ef1b0b2406698607ab1/ProjectSettings/NavMeshLayers.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unitycoder/IndieSoftShadow/41b873d926916ba7a94b6ef1b0b2406698607ab1/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unitycoder/IndieSoftShadow/41b873d926916ba7a94b6ef1b0b2406698607ab1/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unitycoder/IndieSoftShadow/41b873d926916ba7a94b6ef1b0b2406698607ab1/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unitycoder/IndieSoftShadow/41b873d926916ba7a94b6ef1b0b2406698607ab1/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unitycoder/IndieSoftShadow/41b873d926916ba7a94b6ef1b0b2406698607ab1/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unitycoder/IndieSoftShadow/41b873d926916ba7a94b6ef1b0b2406698607ab1/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | IndieSoftShadow 2 | =============== 3 | 4 | Directional light soft shadows for Unity Indie(free) 5 | 6 | http://unitycoder.com/blog/2014/07/15/unity-indie-soft-shadows-directional-light/ 7 | --------------------------------------------------------------------------------