15
2014
Unity indie: Soft Shadows (Directional Light)
Using Unity Indie, modified directional hard light shadows.
Forum thread:
– http://forum.unity3d.com/threads/free-directional-light-soft-shadow-unity-indie.257432/
How to:
– Download builtin shader: http://unity3d.com/unity/download/archive
– copied UnityCG, UnityShaderVariables, HLSLSupport, AutoLight to assets folder
– renamed these as: UnityCG2, UnityShaderVariables2, HLSLSupport2
– created new shader file (that default diffuse)
– add this line to shader: #include “UnityCG2.cginc”
- modified it to use: #include “UnityShaderVariables2.cginc”
– modified that to use: #include “HLSLSupport2.cginc”
– then modified AutoLight for the soft shadow (basically changed all returns to 1, until founded which one it is, then added shadow “blur” there)
– *** Seems that you only need the AutoLight.cginc (in the same folder as the shader, others were not needed)
Sources:
https://github.com/unitycoder/IndieSoftShadow **there are no comments or tutorial yet, check AutoLight.cginc for the modifications..
Webplayer demo:
http://unitycoder.com/upload/demos/HardShadowSoftener/
—
v2: Some progress on getting custom shadows, without any cginc modifications, but something is still broken..
Shader "Custom/IndieShadow1" { Properties { _Color ("Main Color", Color) = (1,1,1,0.5) _MainTex ("Texture", 2D) = "white" { } } SubShader { Pass { CGPROGRAM // Upgrade NOTE: excluded shader from DX11 and Xbox360; has structs without semantics (struct v2f members shadowCoord) #pragma exclude_renderers d3d11 xbox360 #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" float4 _Color; sampler2D _MainTex; sampler2D _ShadowMapTexture; struct v2f { float4 pos : SV_POSITION; float2 uv : TEXCOORD0; float4 shadowCoord; }; float4 _MainTex_ST; v2f vert (appdata_base v) { v2f o; o.pos = mul (UNITY_MATRIX_MVP, v.vertex); o.uv = TRANSFORM_TEX (v.texcoord, _MainTex); // FIXME: problem could be here? o.shadowCoord = mul( unity_World2Shadow[0], mul( _Object2World, v.vertex ) ); return o; } half4 frag (v2f i) : COLOR { half4 texcol = tex2D (_MainTex, i.uv); // Hard Shadow fixed shadow = tex2D(_ShadowMapTexture, i.shadowCoord.xyz).r; shadow = _LightShadowData.r + shadow * (1-_LightShadowData.r); return texcol * _Color * shadow; } ENDCG } } Fallback "VertexLit" }
—
Image#2: closeup
—
Image#3: Inverted shadow (shadow is light), could be useful for some effects?
—
Image#4: Custom shader with inline unitySampleShadow(), without using autolight.inc..currently only works from certain angles..
Related Posts
5 Comments + Add Comment
Leave a comment
Recent posts
- [GreaseMonkey] Unity Forum Fixer
- UnityHub: Make Hub application background Translucent
- Customize SpriteShapeRenderer quality (but has issues)
- Editor tool: Copy selected gameobject’s names into clipboard as rows (for Excel)
- Editor tool: Replace string in selected gameobject’s names
- UnityHub: Enable built-in Login Dialog (no more browser login/logout issues!)
- Use TikTok-TTS in Unity (with WebRequest)
- Create Scene Thumbnail Image using OnSceneSaved & OnPreviewGUI
- webgl+javascript TTS
- Using Moonsharp (LUA) + Unity Webgl
- Using 3D gameobject prefabs with Unity Tilemap + NavMesh Surface
- Custom Unity Hub Project Template Preview Image/Video (using HTML+CSS in package description)
Recent Comments
- Vector3 maths for dummies! on
- UnityHub: Make Hub application background Translucent on
- UnityHub: Make Hub application background Translucent on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- [Asset Store] Point Cloud Viewer & Tools on
- [Asset Store] Point Cloud Viewer & Tools on
- ffmpeg stream raw video into Unity Texture2D on
someone suggested this shader also,
http://armedunity.com/topic/8368-better-soft-shadows-wip/
*seems to be for deferred (which is pro only), but maybe those calculations can be used?
** this shader is same or similar to the ones in builtin shaders zip.
also interesting find, some random texture from unity:
uniform sampler2D unity_RandomRotation16;
modified cgincludes can be put on resources folder, must restart unity after that so that they take effect:
http://forum.unity3d.com/threads/builtin-unity-shaders-source.2085/#post-1702265
smoother autolight.cginc version available here:
http://forum.unity3d.com/threads/free-directional-light-soft-shadow-unity-indie.257432/#post-1708062
about softshadows:
http://codeflow.org/entries/2013/feb/15/soft-shadow-mapping/
[…] Soft Shadows (Directional Light) | Unity Coding […]