diff --git a/CGIncludes/HLSLSupport.cginc b/CGIncludes/HLSLSupport.cginc index 06cfdde..2ba8c25 100644 --- a/CGIncludes/HLSLSupport.cginc +++ b/CGIncludes/HLSLSupport.cginc @@ -397,6 +397,8 @@ // this allows surface shaders to use _NOSAMPLER and similar macros, without using up a sampler register. // Don't do that for mojoshader part, as that one can only parse DX9 style HLSL. + #define UNITY_SEPARATE_TEXTURE_SAMPLER + // 2D textures #define UNITY_DECLARE_TEX2D(tex) Texture2D tex; SamplerState sampler##tex #define UNITY_DECLARE_TEX2D_NOSAMPLER(tex) Texture2D tex diff --git a/CGIncludes/TerrainSplatmapCommon.cginc b/CGIncludes/TerrainSplatmapCommon.cginc index 8be0939..6b5f13f 100644 --- a/CGIncludes/TerrainSplatmapCommon.cginc +++ b/CGIncludes/TerrainSplatmapCommon.cginc @@ -77,10 +77,10 @@ void SplatmapVert(inout appdata_full v, out Input data) v.tangent.xyz = cross(v.normal, float3(0,0,1)); v.tangent.w = -1; - data.tc.xy = v.texcoord; + data.tc.xy = v.texcoord.xy; #ifdef TERRAIN_BASE_PASS #ifdef UNITY_PASS_META - data.tc.xy = v.texcoord * _MainTex_ST.xy + _MainTex_ST.zw; + data.tc.xy = TRANSFORM_TEX(v.texcoord.xy, _MainTex); #endif #else float4 pos = UnityObjectToClipPos(v.vertex); diff --git a/CGIncludes/UnityCG.cginc b/CGIncludes/UnityCG.cginc index 20894c4..d4e35e3 100644 --- a/CGIncludes/UnityCG.cginc +++ b/CGIncludes/UnityCG.cginc @@ -520,7 +520,6 @@ inline half3 DecodeHDR (half4 data, half4 decodeInstructions) // Decodes HDR textures // handles dLDR, RGBM formats -// Called by DecodeLightmap when UNITY_NO_RGBM is not defined. inline half3 DecodeLightmapRGBM (half4 data, half4 decodeInstructions) { // If Linear mode is not supported we can skip exponent part diff --git a/CGIncludes/UnityInstancing.cginc b/CGIncludes/UnityInstancing.cginc index 83b57ed..292ac72 100644 --- a/CGIncludes/UnityInstancing.cginc +++ b/CGIncludes/UnityInstancing.cginc @@ -120,6 +120,8 @@ #define DEFAULT_UNITY_VERTEX_OUTPUT_STEREO uint stereoTargetEyeIndex : SV_RenderTargetArrayIndex; #define DEFAULT_UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output) output.stereoTargetEyeIndex = unity_StereoEyeIndex #endif + #define DEFAULT_UNITY_VERTEX_OUTPUT_STEREO_EYE_INDEX uint stereoTargetEyeIndex : BLENDINDICES0; + #define DEFAULT_UNITY_INITIALIZE_OUTPUT_STEREO_EYE_INDEX(output) output.stereoTargetEyeIndex = unity_StereoEyeIndex; #define DEFAULT_UNITY_TRANSFER_VERTEX_OUTPUT_STEREO(input, output) output.stereoTargetEyeIndex = input.stereoTargetEyeIndex; #define DEFAULT_UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input) unity_StereoEyeIndex = input.stereoTargetEyeIndex; #elif defined(UNITY_STEREO_MULTIVIEW_ENABLED) @@ -134,12 +136,19 @@ #endif #else #define DEFAULT_UNITY_VERTEX_OUTPUT_STEREO + #define DEFAULT_UNITY_VERTEX_OUTPUT_STEREO_EYE_INDEX + #define DEFAULT_UNITY_INITIALIZE_OUTPUT_STEREO_EYE_INDEX(output) #define DEFAULT_UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output) #define DEFAULT_UNITY_TRANSFER_VERTEX_OUTPUT_STEREO(input, output) #define DEFAULT_UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input) #endif - +#if !defined(UNITY_VERTEX_OUTPUT_STEREO_EYE_INDEX) +# define UNITY_VERTEX_OUTPUT_STEREO_EYE_INDEX DEFAULT_UNITY_VERTEX_OUTPUT_STEREO_EYE_INDEX +#endif +#if !defined(UNITY_INITIALIZE_OUTPUT_STEREO_EYE_INDEX) +# define UNITY_INITIALIZE_OUTPUT_STEREO_EYE_INDEX(output) DEFAULT_UNITY_INITIALIZE_OUTPUT_STEREO_EYE_INDEX(output) +#endif #if !defined(UNITY_VERTEX_OUTPUT_STEREO) # define UNITY_VERTEX_OUTPUT_STEREO DEFAULT_UNITY_VERTEX_OUTPUT_STEREO #endif diff --git a/CGIncludes/UnityStereoExtensions.glslinc b/CGIncludes/UnityStereoExtensions.glslinc new file mode 100644 index 0000000..15d99fd --- /dev/null +++ b/CGIncludes/UnityStereoExtensions.glslinc @@ -0,0 +1,16 @@ +// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) + +#ifndef GLSL_STEREO_EXTENSIONS_INCLUDED +#define GLSL_STEREO_EXTENSIONS_INCLUDED + +#ifdef STEREO_MULTIVIEW_ON + #extension GL_OVR_multiview2 : require +#endif + +#ifdef STEREO_INSTANCING_ON + #extension GL_NV_viewport_array2 : enable + #extension GL_AMD_vertex_shader_layer : enable + #extension GL_ARB_fragment_layer_viewport : enable +#endif + +#endif // GLSL_STEREO_EXTENSIONS_INCLUDED diff --git a/CGIncludes/UnityStereoSupport.glslinc b/CGIncludes/UnityStereoSupport.glslinc new file mode 100644 index 0000000..dc92f02 --- /dev/null +++ b/CGIncludes/UnityStereoSupport.glslinc @@ -0,0 +1,57 @@ +// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) + +#ifndef GLSL_STEREO_SETUP_INCLUDED +#define GLSL_STEREO_SETUP_INCLUDED + +#if defined(STEREO_MULTIVIEW_ON) || defined(STEREO_INSTANCING_ON) + layout(std140) uniform UnityStereoGlobals { + mat4 unity_StereoMatrixP[2]; + mat4 unity_StereoMatrixV[2]; + mat4 unity_StereoMatrixInvV[2]; + mat4 unity_StereoMatrixVP[2]; + mat4 unity_StereoCameraProjection[2]; + mat4 unity_StereoCameraInvProjection[2]; + mat4 unity_StereoWorldToCamera[2]; + mat4 unity_StereoCameraToWorld[2]; + vec3 unity_StereoWorldSpaceCameraPos[2]; + vec4 unity_StereoScaleOffset[2]; + }; + layout(std140) uniform UnityStereoEyeIndices { + vec4 unity_StereoEyeIndices[2]; + }; +#endif + +#ifdef VERTEX + #ifdef STEREO_MULTIVIEW_ON + layout(num_views = 2) in; + #endif + + uniform int unity_StereoEyeIndex; + + int SetupStereoEyeIndex() + { + int eyeIndex = unity_StereoEyeIndex; + + #if defined(STEREO_MULTIVIEW_ON) + eyeIndex = int(unity_StereoEyeIndices[gl_ViewID_OVR].x); + #elif defined(STEREO_INSTANCING_ON) + eyeIndex = int(gl_InstanceID & 1); + gl_Layer = eyeIndex; + #endif + + return eyeIndex; + } + + mat4 GetStereoMatrixVP(int eyeIndex) + { + mat4 stereoVP = unity_MatrixVP; + + #if defined(STEREO_MULTIVIEW_ON) || defined(STEREO_INSTANCING_ON) + stereoVP = unity_StereoMatrixVP[eyeIndex]; + #endif + + return stereoVP; + } +#endif + +#endif // GLSL_STEREO_SETUP_INCLUDED diff --git a/CGIncludes/UnityUIE.cginc b/CGIncludes/UnityUIE.cginc new file mode 100644 index 0000000..84a0147 --- /dev/null +++ b/CGIncludes/UnityUIE.cginc @@ -0,0 +1,324 @@ +// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) + +#ifndef UNITY_UIE_INCLUDED +#define UNITY_UIE_INCLUDED + +#ifndef UIE_SKIN_USING_CONSTANTS + #if SHADER_TARGET < 45 + #define UIE_SKIN_USING_CONSTANTS + #endif // SHADER_TARGET < 30 +#endif // UIE_SKIN_USING_CONSTANTS + +#ifndef UIE_RECTCLIP_USING_BUFFER + #if SHADER_TARGET >= 45 + #define UIE_RECTCLIP_USING_BUFFER + #endif // SHADER_TARGET +#endif // UIE_RECTCLIP_USING_BUFFER + +// The value below is only used on older shader targets, and should be configurable for the app at hand to be the smallest possible +#ifndef UIE_SKIN_ELEMS_COUNT_MAX_CONSTANTS +#define UIE_SKIN_ELEMS_COUNT_MAX_CONSTANTS 20 +#endif // UIE_SKIN_ELEMS_COUNT_MAX_CONSTANTS + +#include "UnityCG.cginc" + +sampler2D _MainTex; +float4 _MainTex_ST; +float4 _MainTex_TexelSize; + +sampler2D _FontTex; +float4 _FontTex_ST; + +sampler2D _CustomTex; +float4 _CustomTex_ST; + +fixed4 _Color; +float4 _1PixelClipInvView; // xy in clip space, zw inverse in view space +float4 _Viewport; +float2 _RenderTargetSize; + +struct appdata_t +{ + float4 vertex : POSITION; + float4 color : COLOR; + float2 uv : TEXCOORD0; + float3 idsAndFlags : TEXCOORD1; // x=transform id, y=clipping rect id, z=flags + UNITY_VERTEX_INPUT_INSTANCE_ID +}; + +struct v2f +{ + float4 vertex : SV_POSITION; + fixed4 color : COLOR; + float2 uv : TEXCOORD0; + nointerpolation fixed4 flags : TEXCOORD1; +#ifdef UIE_RECTCLIP_USING_BUFFER + float4 clipping : TEXCOORD2; +#endif + UNITY_VERTEX_OUTPUT_STEREO +}; + +static const float kUIEVertexLastFlagValue = 6.0f; + +struct ClippingData { float4 worldRect, viewRect, skinningRect; }; // x=left, y=bottom, z=right, w=top +struct SkinningData { float4 row0, row1, row2; }; + +float4 skinningToView(float4 pt, SkinningData skinningData) +{ + pt.x = dot(pt, skinningData.row0); + pt.y = dot(pt, skinningData.row1); + pt.z = dot(pt, skinningData.row2); + return pt; +} + +// Returns the view-space offset that must be applied to the vertex to satisfy a minimum displacement constraint. +// embeddedDisplacement Displacement vector that is embedded in vertex, in vertex-space. +// minDisplacement Minimum length of the displacement that must be observed, in pixels. +float2 uie_get_border_offset(float2 displacementVector, float minDisplacement, SkinningData skinningData) +{ + // Compute the displacement length in framebuffer space (unit = 1 pixel). + float2 viewDisplacement = skinningToView(float4(displacementVector, 0, 0), skinningData).xy; + float frameDisplacementLength = length(viewDisplacement * _1PixelClipInvView.zw); + + // We need to meet the minimum displacement requirement before rounding so that we can simply add 1 after rounding + // if we don't meet it anymore. + float newFrameDisplacementLength = max(minDisplacement, frameDisplacementLength); + newFrameDisplacementLength = round(newFrameDisplacementLength); + newFrameDisplacementLength += step(newFrameDisplacementLength, minDisplacement - 0.001); + + // Convert the resulting displacement into an offset. + float changeRatio = newFrameDisplacementLength / (frameDisplacementLength + 0.000001); + float2 viewOffset = (changeRatio - 1) * viewDisplacement; + + return viewOffset; +} + +float4 viewToWorld(float4 pt) +{ + return mul(UNITY_MATRIX_MV, pt); +} + +float4 worldToClip(float4 pt) +{ + return mul(UNITY_MATRIX_P, pt); +} + +float4 skinningToClip(float4 pt, SkinningData skinningData) +{ + pt = skinningToView(pt, skinningData); + return mul(UNITY_MATRIX_MVP, pt); +} + +#ifdef UIE_RECTCLIP_USING_BUFFER + +float4 uie_compute_clipping(SkinningData skinningData, ClippingData clippingData) +{ + // The min/max corners are assuming a UI coordinate system whose origin is at the top-left corner of the screen. + float4 minCorner = float4(clippingData.skinningRect.x, clippingData.skinningRect.y, 0, 1); + float4 maxCorner = float4(clippingData.skinningRect.z, clippingData.skinningRect.w, 0, 1); + + // Apply the fast transform. + minCorner = skinningToView(minCorner, skinningData); + minCorner = minCorner / minCorner.w; + + maxCorner = skinningToView(maxCorner, skinningData); + maxCorner = maxCorner / maxCorner.w; + + // Intersect with the view rect. + minCorner.xy = max(minCorner.xy, clippingData.viewRect.xy); + maxCorner.xy = min(maxCorner.xy, clippingData.viewRect.zw); + maxCorner.xy = max(maxCorner.xy, minCorner.xy); + + // Apply the view transform. + minCorner = viewToWorld(minCorner); + minCorner = minCorner / minCorner.w; + + maxCorner = viewToWorld(maxCorner); + maxCorner = maxCorner / maxCorner.w; + + // Intersect with the world rect. + minCorner.xy = max(minCorner.xy, clippingData.worldRect.xy); + maxCorner.xy = min(maxCorner.xy, clippingData.worldRect.zw); + maxCorner.xy = max(maxCorner.xy, minCorner.xy); + + // Apply the projection. At this point, min/max isn't a representative naming anymore, because the UI projection + // matrix flips the vertical axis upside down, hence the renaming where topLeft and bottomRight are relative to the + // clip-space, where y increases vertically. + float4 topLeft = worldToClip(minCorner); + topLeft = topLeft / topLeft.w; + + float4 bottomRight = worldToClip(maxCorner); + bottomRight = bottomRight / bottomRight.w; + + // We must provide the min/max corners to the fragment shader in the same space as that of the vertex position + // input of the fragment shader. +#if UNITY_UV_STARTS_AT_TOP + // With DirectX, the vertex position input of the fragment shader increases from top to bottom. This is a vertical + // flip compared to the clip space, so we just multiply the y values by -1. + return float4(topLeft.x, -topLeft.y, bottomRight.x, -bottomRight.y); +#else + // With OpenGL, the vertex position input of the fragment shader increases from bottom to top. There is no vertical + // flip involved, but min is bottom-left and max is top-right which we must deduce from our bottomRight and topLeft + // coordinates. + return float4(topLeft.x, bottomRight.y, bottomRight.x, topLeft.y); +#endif // UNITY_UV_STARTS_AT_TOP +} + +void uie_apply_clipping(v2f IN) +{ +#if UNITY_UV_STARTS_AT_TOP + float2 v = IN.vertex.xy - float2(_Viewport.x, _RenderTargetSize.y - _Viewport.y - _Viewport.w); +#else + float2 v = IN.vertex.xy - float2(_Viewport.x, _Viewport.y); +#endif + float2 clipSpacePos = v * _1PixelClipInvView.xy - 1; + float2 minCorner = IN.clipping.xy; + float2 maxCorner = IN.clipping.zw; + + float4 clipValue; + clipValue.xy = clipSpacePos - minCorner; + clipValue.zw = maxCorner - clipSpacePos; + clip(clipValue); +} + +#endif // UIE_RECTCLIP_USING_BUFFER + +float TestForValue(float value, inout float flags) +{ +#if SHADER_API_GLES + float result = saturate(flags - value + 1.0); + flags -= result * value; + return result; +#else + return flags == value; +#endif +} + +v2f uie_std_vert_core(appdata_t v, SkinningData skinningData, ClippingData clippingData) +{ + v2f OUT; + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT); + + float flags = v.idsAndFlags.z; + // Keep the descending order for GLES2 + const float isSVGGradients = TestForValue(5.0, flags); + const float isEdge = TestForValue(4.0, flags); + const float isCustom = TestForValue(3.0, flags); + const float isTextured = TestForValue(2.0, flags); + const float isText = TestForValue(1.0, flags); + + float2 viewOffset = float2(0, 0); + if (isEdge == 1) + viewOffset = uie_get_border_offset(v.uv, 1, skinningData); + + v.vertex = skinningToView(v.vertex, skinningData); + v.vertex.xy += viewOffset; + + OUT.vertex = mul(UNITY_MATRIX_MVP, float4(v.vertex.xyz, 1)); + OUT.uv = TRANSFORM_TEX(v.uv, _MainTex); + if (isTextured == 1.0f && isCustom == 0.0f) + OUT.uv *= _MainTex_TexelSize.xy; + OUT.color = v.color * _Color; + OUT.flags = fixed4(isText, isTextured, isCustom, 1 - saturate(isText + isTextured + isCustom)); + +#ifdef UIE_RECTCLIP_USING_BUFFER + OUT.clipping = uie_compute_clipping(skinningData, clippingData); +#endif // UIE_RECTCLIP_USING_BUFFER + + return OUT; +} + +fixed4 uie_std_frag(v2f IN) +{ +#ifdef UIE_RECTCLIP_USING_BUFFER + uie_apply_clipping(IN); +#endif // UIE_RECTCLIP_USING_BUFFER + + // Extract the flags. + fixed isText = IN.flags.x; + fixed isTextured = IN.flags.y; + fixed isCustom = IN.flags.z; + fixed isSolid = IN.flags.w; + + half4 atlasColor = tex2D(_MainTex, IN.uv) * isTextured; + half4 fontColor = half4(1, 1, 1, tex2D(_FontTex, IN.uv).a) * isText; + half4 customColor = tex2D(_CustomTex, IN.uv) * isCustom; + + half4 texColor = (half4)isSolid + atlasColor + fontColor + customColor; + half4 color = texColor * IN.color; + return color; +} + + +#ifdef UIE_SKIN_USING_CONSTANTS + +CBUFFER_START(UITransforms) +float4 _Transforms[UIE_SKIN_ELEMS_COUNT_MAX_CONSTANTS * 3]; // 3 float4s map to matrix 3 columns (the projection column is ignored) +CBUFFER_END + +SkinningData uie_get_skinning_data(float id) +{ + SkinningData skinningData; + skinningData.row0 = _Transforms[id * 3 + 0]; + skinningData.row1 = _Transforms[id * 3 + 1]; + skinningData.row2 = _Transforms[id * 3 + 2]; + return skinningData; +} + +#else // !UIE_SKIN_USING_CONSTANTS + +struct Transform3x4 { float4 v0, v1, v2; }; +StructuredBuffer _TransformsBuffer; // 3 float4s map to matrix 3 columns (the projection column is ignored) + +SkinningData uie_get_skinning_data(float id) +{ + Transform3x4 transform = _TransformsBuffer[id]; + SkinningData skinningData; + skinningData.row0 = transform.v0; + skinningData.row1 = transform.v1; + skinningData.row2 = transform.v2; + return skinningData; +} + +#endif // UIE_SKIN_USING_CONSTANTS + + +#ifdef UIE_RECTCLIP_USING_BUFFER + +StructuredBuffer _ClippingBuffer; + +ClippingData uie_get_clipping_rect(float id) +{ + return _ClippingBuffer[id]; +} + +#else // !UIE_RECTCLIP_USING_BUFFER + +ClippingData uie_get_clipping_rect(float id) +{ + ClippingData data; + data.worldRect = float4(-1000000, -1000000, 1000000, 1000000); + data.viewRect = float4(-1000000, -1000000, 1000000, 1000000); + data.skinningRect = float4(-1000000, -1000000, 1000000, 1000000); + return data; +} + +#endif + + +v2f uie_std_vert(appdata_t v) +{ + SkinningData skinningData = uie_get_skinning_data(v.idsAndFlags.x); + ClippingData clippingData = uie_get_clipping_rect(v.idsAndFlags.y); + return uie_std_vert_core(v, skinningData, clippingData); +} + +#ifndef UIE_CUSTOM_SHADER + +v2f vert(appdata_t v) { return uie_std_vert(v); } +fixed4 frag(v2f IN) : SV_Target { return uie_std_frag(IN); } + +#endif // UIE_CUSTOM_SHADER + +#endif // UNITY_UIE_INCLUDED diff --git a/DefaultResources/Internal-Skinning.compute b/DefaultResources/Internal-Skinning.compute index c2d7c7a..2af5389 100644 --- a/DefaultResources/Internal-Skinning.compute +++ b/DefaultResources/Internal-Skinning.compute @@ -2,6 +2,10 @@ // Generic compute skinning ... with pos, norm, and tangent skinning +#pragma kernel main SKIN_BONESFORVERT=0 +#pragma kernel main SKIN_BONESFORVERT=0 SKIN_NORM +#pragma kernel main SKIN_BONESFORVERT=0 SKIN_TANG +#pragma kernel main SKIN_BONESFORVERT=0 SKIN_NORM SKIN_TANG #pragma kernel main SKIN_BONESFORVERT=1 #pragma kernel main SKIN_BONESFORVERT=1 SKIN_NORM #pragma kernel main SKIN_BONESFORVERT=1 SKIN_TANG @@ -25,7 +29,7 @@ uint g_VertCount; #define STRUCTURED_BUFFER_SUPPORT 0 #endif -struct SVertInVBO +struct MeshVertex { float3 pos; #if SKIN_NORM @@ -36,116 +40,83 @@ struct SVertInVBO #endif }; -struct SVertInSkin +struct SkinInfluence { -#if SKIN_BONESFORVERT==1 +#if SKIN_BONESFORVERT <= 1 int index0; -#elif SKIN_BONESFORVERT==2 - float weight0,weight1; - int index0,index1; -#elif SKIN_BONESFORVERT==4 - float weight0,weight1,weight2,weight3; - int index0,index1,index2,index3; +#elif SKIN_BONESFORVERT == 2 + float weight0, weight1; + int index0, index1; +#elif SKIN_BONESFORVERT == 4 + float weight0, weight1, weight2, weight3; + int index0, index1, index2, index3; #endif }; - -struct SVertOut -{ - float3 pos; -#if SKIN_NORM - float3 norm; -#endif -#if SKIN_TANG - float4 tang; -#endif -}; - -#if !STRUCTURED_BUFFER_SUPPORT - -SVertInVBO FetchVerts( SAMPLER_UNIFORM Buffer g_SourceVBO, const uint t) -{ - SVertInVBO vert; - - #if SKIN_NORM && SKIN_TANG - const int stride = 10; - const int tangOffset = 6; +#define VERTEX_STRIDE 10 #elif SKIN_NORM - const int stride = 6; -#elif SKIN_TANG - const int stride = 7; - const int tangOffset = 3; +#define VERTEX_STRIDE 6 #else - const int stride = 3; - const int tangOffset = 0; +#define VERTEX_STRIDE 3 #endif - vert.pos.x = g_SourceVBO[t * stride]; - vert.pos.y = g_SourceVBO[t * stride + 1]; - vert.pos.z = g_SourceVBO[t * stride + 2]; + +#if !STRUCTURED_BUFFER_SUPPORT +MeshVertex FetchVert(SAMPLER_UNIFORM Buffer vertices, const uint index, const uint stride) +{ + MeshVertex vert; + + uint offset = index * stride; + vert.pos.x = vertices[offset++]; + vert.pos.y = vertices[offset++]; + vert.pos.z = vertices[offset++]; #if SKIN_NORM - vert.norm.x = g_SourceVBO[t * stride + 3]; - vert.norm.y = g_SourceVBO[t * stride + 4]; - vert.norm.z = g_SourceVBO[t * stride + 5]; + vert.norm.x = vertices[offset++]; + vert.norm.y = vertices[offset++]; + vert.norm.z = vertices[offset++]; #endif #if SKIN_TANG - vert.tang.x = g_SourceVBO[t * stride + tangOffset]; - vert.tang.y = g_SourceVBO[t * stride + tangOffset + 1]; - vert.tang.z = g_SourceVBO[t * stride + tangOffset + 2]; - vert.tang.w = g_SourceVBO[t * stride + tangOffset + 3]; + vert.tang.x = vertices[offset++]; + vert.tang.y = vertices[offset++]; + vert.tang.z = vertices[offset++]; + vert.tang.w = vertices[offset++]; #endif -return vert; - + return vert; } -void StoreVerts( SAMPLER_UNIFORM RWBuffer g_MeshVertsOut, float3 pos, float3 normal, float4 tang, const uint t) +void StoreVert(SAMPLER_UNIFORM RWBuffer vertices, float3 pos, float3 normal, float4 tang, const uint index, const uint stride) { -#if SKIN_NORM && SKIN_TANG - const int stride = 10; - const int tangOffset = 6; -#elif SKIN_NORM - const int stride = 6; -#elif SKIN_TANG - const int stride = 7; - const int tangOffset = 3; -#else - const int stride = 3; - const int tangOffset = 0; -#endif - - g_MeshVertsOut[t * stride] = pos.x; - g_MeshVertsOut[t * stride + 1] = pos.y; - g_MeshVertsOut[t * stride + 2] = pos.z; + uint offset = index * stride; + vertices[offset++] = pos.x; + vertices[offset++] = pos.y; + vertices[offset++] = pos.z; #if SKIN_NORM - g_MeshVertsOut[t * stride + 3]= normal.x; - g_MeshVertsOut[t * stride + 4]= normal.y; - g_MeshVertsOut[t * stride + 5]= normal.z; + vertices[offset++] = normal.x; + vertices[offset++] = normal.y; + vertices[offset++] = normal.z; #endif #if SKIN_TANG - g_MeshVertsOut[t * stride + tangOffset] = tang.x; - g_MeshVertsOut[t * stride + tangOffset + 1] = tang.y; - g_MeshVertsOut[t * stride + tangOffset + 2] = tang.z; - g_MeshVertsOut[t * stride + tangOffset + 3] = tang.w; + vertices[offset++] = tang.x; + vertices[offset++] = tang.y; + vertices[offset++] = tang.z; + vertices[offset++] = tang.w; #endif } #endif -#define NR_THREADS 64 -[numthreads(NR_THREADS, 1, 1)] +[numthreads(64, 1, 1)] #if !STRUCTURED_BUFFER_SUPPORT -void main(uint3 threadID : SV_DispatchThreadID, SAMPLER_UNIFORM Buffer g_SourceVBO, SAMPLER_UNIFORM StructuredBuffer g_SourceSkin, SAMPLER_UNIFORM RWBuffer g_MeshVertsOut, - SAMPLER_UNIFORM StructuredBuffer g_mBones) +void main(uint3 threadID : SV_DispatchThreadID, SAMPLER_UNIFORM Buffer inVertices, SAMPLER_UNIFORM StructuredBuffer inSkin, SAMPLER_UNIFORM RWBuffer outVertices, SAMPLER_UNIFORM StructuredBuffer inMatrices) #else -void main(uint3 threadID : SV_DispatchThreadID, SAMPLER_UNIFORM StructuredBuffer g_SourceVBO, SAMPLER_UNIFORM StructuredBuffer g_SourceSkin, SAMPLER_UNIFORM RWStructuredBuffer g_MeshVertsOut, - SAMPLER_UNIFORM StructuredBuffer g_mBones) +void main(uint3 threadID : SV_DispatchThreadID, SAMPLER_UNIFORM StructuredBuffer inVertices, SAMPLER_UNIFORM StructuredBuffer inSkin, SAMPLER_UNIFORM RWStructuredBuffer outVertices, SAMPLER_UNIFORM StructuredBuffer inMatrices) #endif { const uint t = threadID.x; @@ -156,92 +127,67 @@ void main(uint3 threadID : SV_DispatchThreadID, SAMPLER_UNIFORM StructuredBuffer } #if !STRUCTURED_BUFFER_SUPPORT - const SVertInVBO vert = FetchVerts(g_SourceVBO, t); + const MeshVertex vert = FetchVert(inVertices, t, VERTEX_STRIDE); #else - const SVertInVBO vert = g_SourceVBO[t]; + const MeshVertex vert = inVertices[t]; #endif - SVertInSkin si = g_SourceSkin[t]; // get skinning info. - float3 vP = vert.pos.xyz; - float3 vPacc = float3(0,0,0); + SkinInfluence si = inSkin[t]; - float3 vN = float3(0,0,0); + float3 vPos = vert.pos.xyz; #if SKIN_NORM - vN = vert.norm.xyz; - float3 vNacc = float3(0,0,0); + float3 vNorm = vert.norm.xyz; #endif - - float3 vT = float3(0,0,0); #if SKIN_TANG - vT = vert.tang.xyz; - float3 vTacc = float3(0,0,0); + float3 vTang = vert.tang.xyz; #endif + float3 oPos = float3(0, 0, 0); + float3 oNorm = float3(0, 0, 0); + float4 oTang = float4(0, 0, 0, 0); -#if SKIN_BONESFORVERT==1 - vPacc += mul(g_mBones[si.index0], float4(vP,1) ).xyz; -#elif SKIN_BONESFORVERT==2 - vPacc += si.weight0*mul( g_mBones[si.index0], float4(vP,1) ).xyz; - vPacc += si.weight1*mul( g_mBones[si.index1], float4(vP,1) ).xyz; -#elif SKIN_BONESFORVERT==4 - vPacc += si.weight0*mul( g_mBones[si.index0], float4(vP,1) ).xyz; - vPacc += si.weight1*mul( g_mBones[si.index1], float4(vP,1) ).xyz; - vPacc += si.weight2*mul( g_mBones[si.index2], float4(vP,1) ).xyz; - vPacc += si.weight3*mul( g_mBones[si.index3], float4(vP,1) ).xyz; +#if SKIN_BONESFORVERT == 0 + uint startIndex = si.index0; + uint endIndex = inSkin[t + 1].index0; + float4x4 blendedMatrix = 0; + for (uint i = startIndex; i < endIndex; i++) + { + uint weightAndIndex = inSkin[i].index0; + float weight = float(weightAndIndex >> 16) * (1.0f / 65535.0f); + uint index = weightAndIndex & 0xFFFF; + blendedMatrix += inMatrices[index] * weight; + } +#elif SKIN_BONESFORVERT == 1 + const float4x4 blendedMatrix = inMatrices[si.index0]; +#elif SKIN_BONESFORVERT == 2 + const float4x4 blendedMatrix = inMatrices[si.index0] * si.weight0 + + inMatrices[si.index1] * si.weight1; +#elif SKIN_BONESFORVERT == 4 + const float4x4 blendedMatrix = inMatrices[si.index0] * si.weight0 + + inMatrices[si.index1] * si.weight1 + + inMatrices[si.index2] * si.weight2 + + inMatrices[si.index3] * si.weight3; #endif + oPos = mul(blendedMatrix, float4(vPos, 1)).xyz; + #if SKIN_NORM -#if SKIN_BONESFORVERT==1 - vNacc += mul( g_mBones[si.index0],float4(vN,0) ).xyz; -#elif SKIN_BONESFORVERT==2 - vNacc += si.weight0*mul( g_mBones[si.index0],float4(vN,0) ).xyz; - vNacc += si.weight1*mul( g_mBones[si.index1],float4(vN,0) ).xyz; -#elif SKIN_BONESFORVERT==4 - vNacc += si.weight0*mul( g_mBones[si.index0],float4(vN,0) ).xyz; - vNacc += si.weight1*mul( g_mBones[si.index1],float4(vN,0) ).xyz; - vNacc += si.weight2*mul( g_mBones[si.index2],float4(vN,0) ).xyz; - vNacc += si.weight3*mul( g_mBones[si.index3],float4(vN,0) ).xyz; -#endif + oNorm = mul(blendedMatrix, float4(vNorm, 0)).xyz; #endif #if SKIN_TANG -#if SKIN_BONESFORVERT==1 - vTacc += mul( (float3x3)g_mBones[si.index0], vT ).xyz; -#elif SKIN_BONESFORVERT==2 - vTacc += si.weight0*mul( (float3x3)g_mBones[si.index0], vT ).xyz; - vTacc += si.weight1*mul( (float3x3)g_mBones[si.index1], vT ).xyz; -#elif SKIN_BONESFORVERT==4 - vTacc += si.weight0*mul((float3x3)g_mBones[si.index0], vT ).xyz; - vTacc += si.weight1*mul((float3x3)g_mBones[si.index1], vT ).xyz; - vTacc += si.weight2*mul((float3x3)g_mBones[si.index2], vT ).xyz; - vTacc += si.weight3*mul((float3x3)g_mBones[si.index3], vT ).xyz; -#endif + oTang.xyz = mul(blendedMatrix, float4(vTang, 0)).xyz; + oTang.w = vert.tang.w; #endif - vP = vPacc; #if STRUCTURED_BUFFER_SUPPORT - g_MeshVertsOut[t].pos.xyz = vP; -#endif - + outVertices[t].pos = oPos; #if SKIN_NORM - vN = vNacc; -#if STRUCTURED_BUFFER_SUPPORT - g_MeshVertsOut[t].norm.xyz = vN; -#endif + outVertices[t].norm = oNorm; #endif - #if SKIN_TANG - vT = vTacc; -#if STRUCTURED_BUFFER_SUPPORT - g_MeshVertsOut[t].tang = float4(vT.xyz,vert.tang.w); -#endif + outVertices[t].tang = oTang; #endif - -#if !STRUCTURED_BUFFER_SUPPORT -#if SKIN_TANG - StoreVerts(g_MeshVertsOut, vP, vN, float4(vT.xyz,vert.tang.w), t); #else - StoreVerts(g_MeshVertsOut, vP, vN, float4(0.0f, 0.0f, 0.0f, 0.0f), t); + StoreVert(outVertices, oPos, oNorm, oTang, t, VERTEX_STRIDE); #endif -#endif - } diff --git a/DefaultResources/PerformanceTools/FrameDebuggerRenderTargetDisplay.shader b/DefaultResources/PerformanceTools/FrameDebuggerRenderTargetDisplay.shader index d5b8c38..ddaef8b 100644 --- a/DefaultResources/PerformanceTools/FrameDebuggerRenderTargetDisplay.shader +++ b/DefaultResources/PerformanceTools/FrameDebuggerRenderTargetDisplay.shader @@ -58,7 +58,6 @@ Shader "Hidden/FrameDebuggerRenderTargetDisplay" { ENDCG SubShader { - Tags { "ForceSupported"="True" } Cull Off ZWrite Off ZTest Always // 2D texture diff --git a/DefaultResourcesExtra/AutodeskInteractive.shader b/DefaultResourcesExtra/AutodeskInteractive.shader index 7d5fee5..63b205f 100644 --- a/DefaultResourcesExtra/AutodeskInteractive.shader +++ b/DefaultResourcesExtra/AutodeskInteractive.shader @@ -19,7 +19,7 @@ Shader "Autodesk Interactive" [ToggleOff] _GlossyReflections("Glossy Reflections", Float) = 1.0 _BumpScale("Scale", Float) = 1.0 - _BumpMap("Normal Map", 2D) = "bump" {} + [Normal] _BumpMap("Normal Map", 2D) = "bump" {} _Parallax ("Height Scale", Range (0.005, 0.08)) = 0.02 _ParallaxMap ("Height Map", 2D) = "black" {} @@ -34,7 +34,7 @@ Shader "Autodesk Interactive" _DetailAlbedoMap("Detail Albedo x2", 2D) = "grey" {} _DetailNormalMapScale("Scale", Float) = 1.0 - _DetailNormalMap("Normal Map", 2D) = "bump" {} + [Normal] _DetailNormalMap("Normal Map", 2D) = "bump" {} [Enum(UV0,0,UV1,1)] _UVSec ("UV Set for secondary textures", Float) = 0 @@ -71,14 +71,14 @@ Shader "Autodesk Interactive" // ------------------------------------- #pragma shader_feature _NORMALMAP - #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON #pragma shader_feature _EMISSION - #pragma shader_feature _METALLICGLOSSMAP - #pragma shader_feature _SPECGLOSSMAP - #pragma shader_feature ___ _DETAIL_MULX2 - #pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF - #pragma shader_feature _ _GLOSSYREFLECTIONS_OFF - #pragma shader_feature _PARALLAXMAP + #pragma shader_feature_local _METALLICGLOSSMAP + #pragma shader_feature_local _SPECGLOSSMAP + #pragma shader_feature_local _DETAIL_MULX2 + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _GLOSSYREFLECTIONS_OFF + #pragma shader_feature_local _PARALLAXMAP #pragma multi_compile_fwdbase #pragma multi_compile_fog @@ -107,12 +107,12 @@ Shader "Autodesk Interactive" // ------------------------------------- #pragma shader_feature _NORMALMAP - #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON - #pragma shader_feature _METALLICGLOSSMAP - #pragma shader_feature _SPECGLOSSMAP - #pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF - #pragma shader_feature ___ _DETAIL_MULX2 - #pragma shader_feature _PARALLAXMAP + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _METALLICGLOSSMAP + #pragma shader_feature_local _SPECGLOSSMAP + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _DETAIL_MULX2 + #pragma shader_feature_local _PARALLAXMAP #pragma multi_compile_fwdadd_fullshadows #pragma multi_compile_fog @@ -136,9 +136,9 @@ Shader "Autodesk Interactive" // ------------------------------------- - #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON - #pragma shader_feature _METALLICGLOSSMAP - #pragma shader_feature _PARALLAXMAP + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _METALLICGLOSSMAP + #pragma shader_feature_local _PARALLAXMAP #pragma multi_compile_shadowcaster #pragma multi_compile_instancing @@ -163,13 +163,13 @@ Shader "Autodesk Interactive" // ------------------------------------- #pragma shader_feature _NORMALMAP - #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON #pragma shader_feature _EMISSION - #pragma shader_feature _METALLICGLOSSMAP - #pragma shader_feature _SPECGLOSSMAP - #pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF - #pragma shader_feature ___ _DETAIL_MULX2 - #pragma shader_feature _PARALLAXMAP + #pragma shader_feature_local _METALLICGLOSSMAP + #pragma shader_feature_local _SPECGLOSSMAP + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _DETAIL_MULX2 + #pragma shader_feature_local _PARALLAXMAP #pragma multi_compile_prepassfinal #pragma multi_compile_instancing @@ -197,9 +197,9 @@ Shader "Autodesk Interactive" #pragma fragment frag_meta #pragma shader_feature _EMISSION - #pragma shader_feature _METALLICGLOSSMAP - #pragma shader_feature _SPECGLOSSMAP - #pragma shader_feature ___ _DETAIL_MULX2 + #pragma shader_feature_local _METALLICGLOSSMAP + #pragma shader_feature_local _SPECGLOSSMAP + #pragma shader_feature_local _DETAIL_MULX2 #pragma shader_feature EDITOR_VISUALIZATION #include "UnityStandardMeta.cginc" @@ -225,14 +225,14 @@ Shader "Autodesk Interactive" CGPROGRAM #pragma target 2.0 #pragma shader_feature _NORMALMAP - #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON #pragma shader_feature _EMISSION - #pragma shader_feature _METALLICGLOSSMAP - #pragma shader_feature _SPECGLOSSMAP - #pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF - #pragma shader_feature _ _GLOSSYREFLECTIONS_OFF - // SM2.0: NOT SUPPORTED shader_feature ___ _DETAIL_MULX2 - // SM2.0: NOT SUPPORTED shader_feature _PARALLAXMAP + #pragma shader_feature_local _METALLICGLOSSMAP + #pragma shader_feature_local _SPECGLOSSMAP + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _GLOSSYREFLECTIONS_OFF + // SM2.0: NOT SUPPORTED shader_feature_local _DETAIL_MULX2 + // SM2.0: NOT SUPPORTED shader_feature_local _PARALLAXMAP #pragma skip_variants SHADOWS_SOFT DIRLIGHTMAP_COMBINED @@ -259,12 +259,12 @@ Shader "Autodesk Interactive" CGPROGRAM #pragma target 2.0 #pragma shader_feature _NORMALMAP - #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON - #pragma shader_feature _METALLICGLOSSMAP - #pragma shader_feature _SPECGLOSSMAP - #pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF - // SM2.0: NOT SUPPORTED #pragma shader_feature ___ _DETAIL_MULX2 - // SM2.0: NOT SUPPORTED shader_feature _PARALLAXMAP + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _METALLICGLOSSMAP + #pragma shader_feature_local _SPECGLOSSMAP + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + // SM2.0: NOT SUPPORTED #pragma shader_feature_local _DETAIL_MULX2 + // SM2.0: NOT SUPPORTED shader_feature_local _PARALLAXMAP #pragma skip_variants SHADOWS_SOFT #pragma multi_compile_fwdadd_fullshadows @@ -286,9 +286,9 @@ Shader "Autodesk Interactive" CGPROGRAM #pragma target 2.0 - #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON - #pragma shader_feature _METALLICGLOSSMAP - #pragma shader_feature _SPECGLOSSMAP + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _METALLICGLOSSMAP + #pragma shader_feature_local _SPECGLOSSMAP #pragma skip_variants SHADOWS_SOFT #pragma multi_compile_shadowcaster @@ -315,9 +315,9 @@ Shader "Autodesk Interactive" #pragma fragment frag_meta #pragma shader_feature _EMISSION - #pragma shader_feature _METALLICGLOSSMAP - #pragma shader_feature _SPECGLOSSMAP - #pragma shader_feature ___ _DETAIL_MULX2 + #pragma shader_feature_local _METALLICGLOSSMAP + #pragma shader_feature_local _SPECGLOSSMAP + #pragma shader_feature_local _DETAIL_MULX2 #pragma shader_feature EDITOR_VISUALIZATION #include "UnityStandardMeta.cginc" diff --git a/DefaultResourcesExtra/Cubemaps/CubeBlur.shader b/DefaultResourcesExtra/Cubemaps/CubeBlur.shader index 8d46391..8f8ea94 100644 --- a/DefaultResourcesExtra/Cubemaps/CubeBlur.shader +++ b/DefaultResourcesExtra/Cubemaps/CubeBlur.shader @@ -55,220 +55,281 @@ Shader "Hidden/CubeBlur" { return exp(-v*v); } - half4 frag(v2f i) : SV_Target + half4 frag_default(v2f i) { - #if (SHADER_TARGET < 30 || SHADER_API_GLES) - return UNITY_SAMPLE_TEXCUBE_LOD(_MainTex, i.uvw.xyz, _Level); - #else - half3 st; + half3 st; + + half3 face = lerp(zero, i.uvw.xyz, abs(i.uvw.xyz)==one); + half3 u = face.zxy*_Texel; + half3 v = face.yzx*_Texel; + half4 s = half4(i.uvw.xyz*(one - abs(face)), 0.); + + // modulate coefficients based on position (texel density on projected sphere) + half w = 1. / sqrt(1. + dot(s.xyz, s.xyz)); + half3 C = gauss(w*w*w); - half3 face = lerp(zero, i.uvw.xyz, abs(i.uvw.xyz)==one); - half3 u = face.zxy*_Texel; - half3 v = face.yzx*_Texel; - half4 s = half4(i.uvw.xyz*(one - abs(face)), 0.); + half4 s1, s2, s3; + half3 c; - // modulate coefficients based on position (texel density on projected sphere) - half w = 1. / sqrt(1. + dot(s.xyz, s.xyz)); - half3 C = gauss(w*w*w); + half3 up1 = fold(i.uvw.xyz + 1.5*u, face); + half3 um1 = fold(i.uvw.xyz - 1.5*u, face); + half3 up2 = fold(i.uvw.xyz + 2.5*u, face); + half3 um2 = fold(i.uvw.xyz - 2.5*u, face); - half4 s1, s2, s3; - half3 c; + half3 vp1 = fold(i.uvw.xyz + 1.5*v, face); + half3 vm1 = fold(i.uvw.xyz - 1.5*v, face); + half3 vp2 = fold(i.uvw.xyz + 2.5*v, face); + half3 vm2 = fold(i.uvw.xyz - 2.5*v, face); - half3 up1 = fold(i.uvw.xyz + 1.5*u, face); - half3 um1 = fold(i.uvw.xyz - 1.5*u, face); - half3 up2 = fold(i.uvw.xyz + 2.5*u, face); - half3 um2 = fold(i.uvw.xyz - 2.5*u, face); + s = 0.; + w = 0.; - half3 vp1 = fold(i.uvw.xyz + 1.5*v, face); - half3 vm1 = fold(i.uvw.xyz - 1.5*v, face); - half3 vp2 = fold(i.uvw.xyz + 2.5*v, face); - half3 vm2 = fold(i.uvw.xyz - 2.5*v, face); + // first row - s = 0.; - w = 0.; + c = C.xyz*C.zzz; - // first row + st = i.uvw.xyz - 2.5*u - 2.5*v; + st = fold(st, face); + s3 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - c = C.xyz*C.zzz; + st = i.uvw.xyz - 1.5*u - 2.5*v; + st = fold(st, face); + s2 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - st = i.uvw.xyz - 2.5*u - 2.5*v; - st = fold(st, face); - s3 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + st = vm2 - .5*u; + s1 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - st = i.uvw.xyz - 1.5*u - 2.5*v; - st = fold(st, face); - s2 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + st = vm2 + .5*u; + s1 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - st = vm2 - .5*u; - s1 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + st = i.uvw.xyz + 1.5*u - 2.5*v; + st = fold(st, face); + s2 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - st = vm2 + .5*u; - s1 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + st = i.uvw.xyz + 2.5*u - 2.5*v; + st = fold(st, face); + s3 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - st = i.uvw.xyz + 1.5*u - 2.5*v; - st = fold(st, face); - s2 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + w += dot(c, two); + s1 = c.x*s1 + c.y*s2; + s += c.z*s3; + s += s1; - st = i.uvw.xyz + 2.5*u - 2.5*v; - st = fold(st, face); - s3 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + // second row - w += dot(c, two); - s1 = c.x*s1 + c.y*s2; - s += c.z*s3; - s += s1; + c = C.xyz*C.yyy; - // second row + st = i.uvw.xyz + 2.5*u - 1.5*v; + st = fold(st, face); + s3 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - c = C.xyz*C.yyy; + st = i.uvw.xyz + 1.5*u - 1.5*v; + st = fold(st, face); + s2 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - st = i.uvw.xyz + 2.5*u - 1.5*v; - st = fold(st, face); - s3 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + st = vm1 + .5*u; + s1 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - st = i.uvw.xyz + 1.5*u - 1.5*v; - st = fold(st, face); - s2 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + st = vm1 - .5*u; + s1 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - st = vm1 + .5*u; - s1 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + st = i.uvw.xyz - 1.5*u - 1.5*v; + st = fold(st, face); + s2 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - st = vm1 - .5*u; - s1 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + st = i.uvw.xyz - 2.5*u - 1.5*v; + st = fold(st, face); + s3 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - st = i.uvw.xyz - 1.5*u - 1.5*v; - st = fold(st, face); - s2 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + w += dot(c, two); + s1 = c.x*s1 + c.y*s2; + s += c.z*s3; + s += s1; - st = i.uvw.xyz - 2.5*u - 1.5*v; - st = fold(st, face); - s3 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + // third row - w += dot(c, two); - s1 = c.x*s1 + c.y*s2; - s += c.z*s3; - s += s1; + c = C.xyz*C.xxx; - // third row + st = um2 - .5*v; + s3 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - c = C.xyz*C.xxx; + st = um1 - .5*v; + s2 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - st = um2 - .5*v; - s3 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + st = i.uvw.xyz - .5*u - .5*v; + s1 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - st = um1 - .5*v; - s2 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + st = i.uvw.xyz + .5*u - .5*v; + s1 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - st = i.uvw.xyz - .5*u - .5*v; - s1 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + st = up1 - .5*v; + s2 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - st = i.uvw.xyz + .5*u - .5*v; - s1 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + st = up2 - .5*v; + s3 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - st = up1 - .5*v; - s2 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + w += dot(c, two); + s1 = c.x*s1 + c.y*s2; + s += c.z*s3; + s += s1; - st = up2 - .5*v; - s3 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + // fourth row - w += dot(c, two); - s1 = c.x*s1 + c.y*s2; - s += c.z*s3; - s += s1; + c = C.xyz*C.xxx; - // fourth row + st = up2 + .5*v; + s3 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - c = C.xyz*C.xxx; + st = up1 + .5*v; + s2 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - st = up2 + .5*v; - s3 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + st = i.uvw.xyz + .5*u + .5*v; + s1 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - st = up1 + .5*v; - s2 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + st = i.uvw.xyz - .5*u + .5*v; + s1 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - st = i.uvw.xyz + .5*u + .5*v; - s1 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + st = um1 + .5*v; + s2 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - st = i.uvw.xyz - .5*u + .5*v; - s1 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + st = um2 + .5*v; + s3 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - st = um1 + .5*v; - s2 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + w += dot(c, two); + s1 = c.x*s1 + c.y*s2; + s += c.z*s3; + s += s1; - st = um2 + .5*v; - s3 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + // fifth row - w += dot(c, two); - s1 = c.x*s1 + c.y*s2; - s += c.z*s3; - s += s1; + c = C.xyz*C.yyy; - // fifth row + st = i.uvw.xyz - 2.5*u + 1.5*v; + st = fold(st, face); + s3 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - c = C.xyz*C.yyy; + st = i.uvw.xyz - 1.5*u + 1.5*v; + st = fold(st, face); + s2 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - st = i.uvw.xyz - 2.5*u + 1.5*v; - st = fold(st, face); - s3 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + st = vp1 - .5*u; + s1 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - st = i.uvw.xyz - 1.5*u + 1.5*v; - st = fold(st, face); - s2 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + st = vp1 + .5*u; + s1 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - st = vp1 - .5*u; - s1 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + st = i.uvw.xyz + 1.5*u + 1.5*v; + st = fold(st, face); + s2 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - st = vp1 + .5*u; - s1 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + st = i.uvw.xyz + 2.5*u + 1.5*v; + st = fold(st, face); + s3 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - st = i.uvw.xyz + 1.5*u + 1.5*v; - st = fold(st, face); - s2 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + w += dot(c, two); + s1 = c.x*s1 + c.y*s2; + s += c.z*s3; + s += s1; - st = i.uvw.xyz + 2.5*u + 1.5*v; - st = fold(st, face); - s3 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + // sixth row - w += dot(c, two); - s1 = c.x*s1 + c.y*s2; - s += c.z*s3; - s += s1; + c = C.xyz*C.zzz; - // sixth row + st = i.uvw.xyz + 2.5*u + 2.5*v; + st = fold(st, face); + s3 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - c = C.xyz*C.zzz; + st = i.uvw.xyz + 1.5*u + 2.5*v; + st = fold(st, face); + s2 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - st = i.uvw.xyz + 2.5*u + 2.5*v; - st = fold(st, face); - s3 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + st = vp2 + .5*u; + s1 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - st = i.uvw.xyz + 1.5*u + 2.5*v; - st = fold(st, face); - s2 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + st = vp2 - .5*u; + s1 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - st = vp2 + .5*u; - s1 = UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + st = i.uvw.xyz - 1.5*u + 2.5*v; + st = fold(st, face); + s2 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - st = vp2 - .5*u; - s1 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + st = i.uvw.xyz - 2.5*u + 2.5*v; + st = fold(st, face); + s3 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); - st = i.uvw.xyz - 1.5*u + 2.5*v; - st = fold(st, face); - s2 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + w += dot(c, two); + s1 = c.x*s1 + c.y*s2; + s += c.z*s3; + s += s1; + + return s/w; + } + + half4 frag_loop(v2f i) + { + half3 face = lerp(zero, i.uvw.xyz, abs(i.uvw.xyz) == one); + half3 u = face.zxy*_Texel; + half3 v = face.yzx*_Texel; + half3 s = i.uvw.xyz*(one - abs(face)); + + // modulate coefficients based on position (texel density on projected sphere) + half w = 1. / sqrt(1. + dot(s, s)); + half3 C = gauss(w*w*w); + + half3 accuColor = half3(0.0, 0.0, 0.0); + half accuWeight = 0.0; + + for (int y = 2; y >= 0; --y) + { + for (int iy = 0; iy < 2; iy++) + { + half ySign = iy * 2 - 1; + half fy = ySign * (half(y)+0.5h); + + for (int x = 2; x >= 0; --x) + { + half3 rgb = half3(0.0, 0.0, 0.0); + UNITY_UNROLL for (int ix = 0; ix < 2; ix++) + { + half xSign = ix * 2 - 1; + half fx = xSign * (half(x) + 0.5h); + + half3 uvw = i.uvw.xyz + fx * u + fy * v; + uvw = fold(uvw, face); + rgb += UNITY_SAMPLE_TEXCUBE_LOD(_MainTex, uvw, _Level).rgb; + } + + half weight = C[x] * C[y]; + accuColor += rgb * weight; + accuWeight += weight * 2; + } + } + } - st = i.uvw.xyz - 2.5*u + 2.5*v; - st = fold(st, face); - s3 += UNITY_SAMPLE_TEXCUBE_LOD_CLAMPED(_MainTex, st, _Level); + half4 result = half4(accuColor / accuWeight, 1.0); - w += dot(c, two); - s1 = c.x*s1 + c.y*s2; - s += c.z*s3; - s += s1; + return result; + } - return s/w; + half4 frag_noblur(v2f i) + { + return UNITY_SAMPLE_TEXCUBE_LOD(_MainTex, i.uvw.xyz, _Level); + } + half4 frag(v2f i) : SV_Target + { + #if (SHADER_TARGET < 30 || defined(SHADER_API_GLES)) + return frag_noblur(i); + #elif defined(SHADER_API_GLES3) || (defined(SHADER_API_VULKAN) && defined(SHADER_API_MOBILE)) + // frag_default uses too many registers for Mali, register spilling makes it load/store bound + // This path also does not blur the alpha channel and it does not clamp the sampled color to values >= 0 + return frag_loop(i); + #else + // TODO: check if frag_loop performs well on all platforms so it could replace frag_default + return frag_default(i); #endif } + ENDCG SubShader { diff --git a/DefaultResourcesExtra/Internal-GUITexture.shader b/DefaultResourcesExtra/Internal-GUITexture.shader index 51ca69f..977079e 100644 --- a/DefaultResourcesExtra/Internal-GUITexture.shader +++ b/DefaultResourcesExtra/Internal-GUITexture.shader @@ -49,7 +49,7 @@ Shader "Hidden/Internal-GUITexture" SubShader { - Tags { "ForceSupported" = "True" "RenderType"="Overlay" } + Tags { "RenderType"="Overlay" } Lighting Off Blend SrcAlpha OneMinusSrcAlpha, One One @@ -65,7 +65,7 @@ Shader "Hidden/Internal-GUITexture" SubShader { - Tags { "ForceSupported" = "True" "RenderType"="Overlay" } + Tags { "RenderType"="Overlay" } Lighting Off Blend SrcAlpha OneMinusSrcAlpha diff --git a/DefaultResourcesExtra/Internal-GUITextureBlit.shader b/DefaultResourcesExtra/Internal-GUITextureBlit.shader index c74891c..2baa4ea 100644 --- a/DefaultResourcesExtra/Internal-GUITextureBlit.shader +++ b/DefaultResourcesExtra/Internal-GUITextureBlit.shader @@ -63,8 +63,6 @@ Shader "Hidden/Internal-GUITextureBlit" ENDCG SubShader { - Tags { "ForceSupported" = "True" } - Lighting Off Blend SrcAlpha OneMinusSrcAlpha, One One Cull Off @@ -78,8 +76,6 @@ Shader "Hidden/Internal-GUITextureBlit" } SubShader { - Tags { "ForceSupported" = "True" } - Lighting Off Blend SrcAlpha OneMinusSrcAlpha Cull Off diff --git a/DefaultResourcesExtra/Internal-GUITextureClip.shader b/DefaultResourcesExtra/Internal-GUITextureClip.shader index a64eeea..4708a5b 100644 --- a/DefaultResourcesExtra/Internal-GUITextureClip.shader +++ b/DefaultResourcesExtra/Internal-GUITextureClip.shader @@ -62,9 +62,6 @@ Shader "Hidden/Internal-GUITextureClip" ENDCG SubShader { - - Tags { "ForceSupported" = "True" } - Lighting Off Blend SrcAlpha OneMinusSrcAlpha, One One Cull Off @@ -78,9 +75,6 @@ Shader "Hidden/Internal-GUITextureClip" } SubShader { - - Tags { "ForceSupported" = "True" } - Lighting Off Blend SrcAlpha OneMinusSrcAlpha Cull Off diff --git a/DefaultResourcesExtra/Internal-GUITextureClipText.shader b/DefaultResourcesExtra/Internal-GUITextureClipText.shader index 71c54c2..ed947f2 100644 --- a/DefaultResourcesExtra/Internal-GUITextureClipText.shader +++ b/DefaultResourcesExtra/Internal-GUITextureClipText.shader @@ -56,8 +56,6 @@ Shader "Hidden/Internal-GUITextureClipText" ENDCG SubShader { - Tags { "ForceSupported" = "True" } - Lighting Off Blend SrcAlpha OneMinusSrcAlpha, One OneMinusSrcAlpha Cull Off @@ -71,8 +69,6 @@ Shader "Hidden/Internal-GUITextureClipText" } SubShader { - Tags { "ForceSupported" = "True" } - Lighting Off Blend SrcAlpha OneMinusSrcAlpha Cull Off diff --git a/DefaultResourcesExtra/Internal-UIRAtlasBlitCopy.shader b/DefaultResourcesExtra/Internal-UIRAtlasBlitCopy.shader new file mode 100644 index 0000000..f0305c6 --- /dev/null +++ b/DefaultResourcesExtra/Internal-UIRAtlasBlitCopy.shader @@ -0,0 +1,137 @@ +// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) + +Shader "Hidden/Internal-UIRAtlasBlitCopy" +{ + Properties + { + _MainTex0("Texture", any) = "" {} + _MainTex1("Texture", any) = "" {} + _MainTex2("Texture", any) = "" {} + _MainTex3("Texture", any) = "" {} + _MainTex4("Texture", any) = "" {} + _MainTex5("Texture", any) = "" {} + _MainTex6("Texture", any) = "" {} + _MainTex7("Texture", any) = "" {} + } + SubShader + { + Pass + { + ZTest Always Cull Off ZWrite Off + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #include "UnityCG.cginc" + + uniform sampler2D _MainTex0; + uniform float4 _MainTex0_ST; + + uniform sampler2D _MainTex1; + uniform float4 _MainTex1_ST; + + uniform sampler2D _MainTex2; + uniform float4 _MainTex2_ST; + + uniform sampler2D _MainTex3; + uniform float4 _MainTex3_ST; + + uniform sampler2D _MainTex4; + uniform float4 _MainTex4_ST; + + uniform sampler2D _MainTex5; + uniform float4 _MainTex5_ST; + + uniform sampler2D _MainTex6; + uniform float4 _MainTex6_ST; + + uniform sampler2D _MainTex7; + uniform float4 _MainTex7_ST; + + struct appdata_t + { + float4 vertex : POSITION; + float3 texcoord : TEXCOORD0; + }; + + struct v2f + { + float4 vertex : SV_POSITION; + float3 texcoord : TEXCOORD0; + }; + + v2f vert (appdata_t v) + { + v2f o; + o.vertex = UnityObjectToClipPos(v.vertex); + switch (v.texcoord.z) + { + case 0: + o.texcoord.xy = TRANSFORM_TEX(v.texcoord.xy, _MainTex0); + break; + case 1: + o.texcoord.xy = TRANSFORM_TEX(v.texcoord.xy, _MainTex1); + break; + case 2: + o.texcoord.xy = TRANSFORM_TEX(v.texcoord.xy, _MainTex2); + break; + case 3: + o.texcoord.xy = TRANSFORM_TEX(v.texcoord.xy, _MainTex3); + break; + case 4: + o.texcoord.xy = TRANSFORM_TEX(v.texcoord.xy, _MainTex4); + break; + case 5: + o.texcoord.xy = TRANSFORM_TEX(v.texcoord.xy, _MainTex5); + break; + case 6: + o.texcoord.xy = TRANSFORM_TEX(v.texcoord.xy, _MainTex6); + break; + case 7: + o.texcoord.xy = TRANSFORM_TEX(v.texcoord.xy, _MainTex7); + break; + default: + o.texcoord.xy = float2(0, 0); + break; + } + o.texcoord.z = v.texcoord.z; + return o; + } + + fixed4 frag(v2f i) : SV_Target + { + fixed4 color = fixed4(1, 1, 1, 1); + switch (i.texcoord.z) + { + case 0: + color = tex2D(_MainTex0, i.texcoord.xy); + break; + case 1: + color = tex2D(_MainTex1, i.texcoord.xy); + break; + case 2: + color = tex2D(_MainTex2, i.texcoord.xy); + break; + case 3: + color = tex2D(_MainTex3, i.texcoord.xy); + break; + case 4: + color = tex2D(_MainTex4, i.texcoord.xy); + break; + case 5: + color = tex2D(_MainTex5, i.texcoord.xy); + break; + case 6: + color = tex2D(_MainTex6, i.texcoord.xy); + break; + case 7: + color = tex2D(_MainTex7, i.texcoord.xy); + break; + } + return color; + } + ENDCG + } + } + Fallback Off +} diff --git a/DefaultResourcesExtra/Internal-UIRDefault.shader b/DefaultResourcesExtra/Internal-UIRDefault.shader new file mode 100644 index 0000000..5bef00b --- /dev/null +++ b/DefaultResourcesExtra/Internal-UIRDefault.shader @@ -0,0 +1,89 @@ +// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) + +Shader "Hidden/Internal-UIRDefault" +{ + Properties + { + // Establish sensible default values + [HideInInspector] _MainTex("Atlas", 2D) = "white" {} + [HideInInspector] _FontTex("Font", 2D) = "black" {} + [HideInInspector] _CustomTex("Custom", 2D) = "black" {} + [HideInInspector] _Color("Tint", Color) = (1,1,1,1) + + // The ortho matrix used to draw 2D UI causes the Y coordinate to flip which also reverses the winding order, + // so our two-sided stencil is setup accordingly (front settings are swapped with back settings). + // When drawing in perspective, then these settings are flipped. + [HideInInspector] _StencilCompFront("__scf", Float) = 3.0 // Equal + [HideInInspector] _StencilPassFront("__spf", Float) = 0.0 // Keep + [HideInInspector] _StencilZFailFront("__szf", Float) = 1.0 // Zero + [HideInInspector] _StencilFailFront("__sff", Float) = 0.0 // Keep + + [HideInInspector] _StencilCompBack("__scb", Float) = 8.0 // Always + [HideInInspector] _StencilPassBack("__spb", Float) = 0.0 // Keep + [HideInInspector] _StencilZFailBack("__szb", Float) = 2.0 // Replace + [HideInInspector] _StencilFailBack("__sfb", Float) = 0.0 // Keep + } + + Category + { + Lighting Off + Blend SrcAlpha OneMinusSrcAlpha + + // Users pass depth between [Near,Far] = [-1,1]. This gets stored on the depth buffer in [Near,Far] [0,1] regardless of the underlying graphics API. + Cull Off // Two sided rendering is crucial for immediate clipping + ZTest GEqual + ZWrite Off + Stencil + { + Ref 255 // 255 for ease of visualization in RenderDoc, but can be just one bit + ReadMask 255 + WriteMask 255 + + CompFront[_StencilCompFront] + PassFront[_StencilPassFront] + ZFailFront[_StencilZFailFront] + FailFront[_StencilFailFront] + + CompBack[_StencilCompBack] + PassBack[_StencilPassBack] + ZFailBack[_StencilZFailBack] + FailBack[_StencilFailBack] + } + + Tags + { + "Queue" = "Transparent" + "IgnoreProjector" = "True" + "RenderType" = "Transparent" + "PreviewType" = "Plane" + } + + // SM4.5 version + SubShader + { + Pass + { + CGPROGRAM + #pragma target 4.5 + #pragma vertex vert + #pragma fragment frag + #include "UnityUIE.cginc" + ENDCG + } + } + + // SM2 version + SubShader + { + Pass + { + CGPROGRAM + #pragma target 2.0 + #pragma vertex vert + #pragma fragment frag + #include "UnityUIE.cginc" + ENDCG + } + } + } // Category +} diff --git a/DefaultResourcesExtra/Nature/SpeedTree.shader b/DefaultResourcesExtra/Nature/SpeedTree.shader index d70ee9f..2541c04 100644 --- a/DefaultResourcesExtra/Nature/SpeedTree.shader +++ b/DefaultResourcesExtra/Nature/SpeedTree.shader @@ -32,9 +32,9 @@ Shader "Nature/SpeedTree" #pragma target 3.0 #pragma instancing_options assumeuniformscaling maxcount:50 #pragma multi_compile_vertex LOD_FADE_PERCENTAGE - #pragma shader_feature GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH - #pragma shader_feature EFFECT_BUMP - #pragma shader_feature EFFECT_HUE_VARIATION + #pragma shader_feature_local GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH + #pragma shader_feature_local EFFECT_BUMP + #pragma shader_feature_local EFFECT_HUE_VARIATION #define ENABLE_WIND #include "SpeedTreeCommon.cginc" @@ -58,7 +58,7 @@ Shader "Nature/SpeedTree" #pragma multi_compile_vertex LOD_FADE_PERCENTAGE LOD_FADE_CROSSFADE #pragma multi_compile_fragment __ LOD_FADE_CROSSFADE #pragma multi_compile_instancing - #pragma shader_feature GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH + #pragma shader_feature_local GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH #pragma multi_compile_shadowcaster #define ENABLE_WIND #include "SpeedTreeCommon.cginc" @@ -113,8 +113,8 @@ Shader "Nature/SpeedTree" #pragma multi_compile_vertex LOD_FADE_PERCENTAGE LOD_FADE_CROSSFADE #pragma multi_compile_fragment __ LOD_FADE_CROSSFADE #pragma multi_compile_instancing - #pragma shader_feature GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH - #pragma shader_feature EFFECT_HUE_VARIATION + #pragma shader_feature_local GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH + #pragma shader_feature_local EFFECT_HUE_VARIATION #define ENABLE_WIND #include "SpeedTreeCommon.cginc" @@ -170,7 +170,7 @@ Shader "Nature/SpeedTree" CGPROGRAM #pragma surface surf Lambert vertex:SpeedTreeVert nodirlightmap nodynlightmap fullforwardshadows noinstancing #pragma multi_compile_vertex LOD_FADE_PERCENTAGE - #pragma shader_feature GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH + #pragma shader_feature_local GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH #include "SpeedTreeCommon.cginc" void surf(Input IN, inout SurfaceOutput OUT) @@ -189,7 +189,7 @@ Shader "Nature/SpeedTree" #pragma vertex vert #pragma fragment frag #pragma multi_compile_vertex LOD_FADE_PERCENTAGE - #pragma shader_feature GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH + #pragma shader_feature_local GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH #pragma multi_compile_shadowcaster #include "SpeedTreeCommon.cginc" @@ -231,7 +231,7 @@ Shader "Nature/SpeedTree" #pragma fragment frag #pragma multi_compile_fog #pragma multi_compile_vertex LOD_FADE_PERCENTAGE - #pragma shader_feature GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH + #pragma shader_feature_local GEOM_TYPE_BRANCH GEOM_TYPE_BRANCH_DETAIL GEOM_TYPE_FROND GEOM_TYPE_LEAF GEOM_TYPE_MESH #include "SpeedTreeCommon.cginc" struct v2f @@ -266,6 +266,7 @@ Shader "Nature/SpeedTree" } } + Dependency "BillboardShader" = "Nature/SpeedTree Billboard" FallBack "Transparent/Cutout/VertexLit" CustomEditor "SpeedTreeMaterialInspector" } diff --git a/DefaultResourcesExtra/Nature/SpeedTree8.shader b/DefaultResourcesExtra/Nature/SpeedTree8.shader index 730a3e2..d69b0b8 100644 --- a/DefaultResourcesExtra/Nature/SpeedTree8.shader +++ b/DefaultResourcesExtra/Nature/SpeedTree8.shader @@ -47,12 +47,12 @@ Shader "Nature/SpeedTree8" #pragma multi_compile_vertex LOD_FADE_PERCENTAGE #pragma instancing_options assumeuniformscaling maxcount:50 - #pragma shader_feature _WINDQUALITY_NONE _WINDQUALITY_FASTEST _WINDQUALITY_FAST _WINDQUALITY_BETTER _WINDQUALITY_BEST _WINDQUALITY_PALM - #pragma shader_feature EFFECT_BILLBOARD - #pragma shader_feature EFFECT_HUE_VARIATION - #pragma shader_feature EFFECT_SUBSURFACE - #pragma shader_feature EFFECT_BUMP - #pragma shader_feature EFFECT_EXTRA_TEX + #pragma shader_feature_local _WINDQUALITY_NONE _WINDQUALITY_FASTEST _WINDQUALITY_FAST _WINDQUALITY_BETTER _WINDQUALITY_BEST _WINDQUALITY_PALM + #pragma shader_feature_local EFFECT_BILLBOARD + #pragma shader_feature_local EFFECT_HUE_VARIATION + #pragma shader_feature_local EFFECT_SUBSURFACE + #pragma shader_feature_local EFFECT_BUMP + #pragma shader_feature_local EFFECT_EXTRA_TEX #define ENABLE_WIND #define EFFECT_BACKSIDE_NORMALS @@ -77,8 +77,8 @@ Shader "Nature/SpeedTree8" CGPROGRAM #pragma surface SpeedTreeSurf Standard vertex:SpeedTreeVert addshadow noinstancing #pragma multi_compile_vertex LOD_FADE_PERCENTAGE - #pragma shader_feature EFFECT_BILLBOARD - #pragma shader_feature EFFECT_EXTRA_TEX + #pragma shader_feature_local EFFECT_BILLBOARD + #pragma shader_feature_local EFFECT_EXTRA_TEX #include "SpeedTree8Common.cginc" diff --git a/DefaultResourcesExtra/Nature/SpeedTreeBillboard.shader b/DefaultResourcesExtra/Nature/SpeedTreeBillboard.shader index 89d3f7b..aae9d7f 100644 --- a/DefaultResourcesExtra/Nature/SpeedTreeBillboard.shader +++ b/DefaultResourcesExtra/Nature/SpeedTreeBillboard.shader @@ -28,8 +28,8 @@ Shader "Nature/SpeedTree Billboard" #pragma surface surf Lambert vertex:SpeedTreeBillboardVert nodirlightmap nodynlightmap addshadow noinstancing dithercrossfade #pragma target 3.0 #pragma multi_compile __ BILLBOARD_FACE_CAMERA_POS - #pragma shader_feature EFFECT_BUMP - #pragma shader_feature EFFECT_HUE_VARIATION + #pragma shader_feature_local EFFECT_BUMP + #pragma shader_feature_local EFFECT_HUE_VARIATION #define ENABLE_WIND #include "SpeedTreeBillboardCommon.cginc" @@ -52,7 +52,7 @@ Shader "Nature/SpeedTree Billboard" #pragma multi_compile_fog #pragma multi_compile __ LOD_FADE_CROSSFADE #pragma multi_compile __ BILLBOARD_FACE_CAMERA_POS - #pragma shader_feature EFFECT_HUE_VARIATION + #pragma shader_feature_local EFFECT_HUE_VARIATION #define ENABLE_WIND #include "SpeedTreeBillboardCommon.cginc" @@ -102,7 +102,7 @@ Shader "Nature/SpeedTree Billboard" CGPROGRAM #pragma surface surf Lambert vertex:SpeedTreeBillboardVert nodirlightmap nodynlightmap noinstancing - #pragma shader_feature EFFECT_BUMP + #pragma shader_feature_local EFFECT_BUMP #include "SpeedTreeBillboardCommon.cginc" void surf(Input IN, inout SurfaceOutput OUT) diff --git a/DefaultResourcesExtra/Particle Standard Surface.shader b/DefaultResourcesExtra/Particle Standard Surface.shader index ceb52fd..74858a9 100644 --- a/DefaultResourcesExtra/Particle Standard Surface.shader +++ b/DefaultResourcesExtra/Particle Standard Surface.shader @@ -73,9 +73,9 @@ Shader "Particles/Standard Surface" CGPROGRAM #pragma target 3.0 - #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON _ALPHAMODULATE_ON - #pragma shader_feature _METALLICGLOSSMAP - #pragma shader_feature _REQUIRE_UV2 + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON _ALPHAMODULATE_ON + #pragma shader_feature_local _METALLICGLOSSMAP + #pragma shader_feature_local _REQUIRE_UV2 #pragma multi_compile_shadowcaster #pragma multi_compile_instancing #pragma instancing_options procedural:vertInstancingSetup @@ -100,8 +100,8 @@ Shader "Particles/Standard Surface" CGPROGRAM #pragma target 3.0 - #pragma shader_feature _ _ALPHATEST_ON - #pragma shader_feature _REQUIRE_UV2 + #pragma shader_feature_local _ALPHATEST_ON + #pragma shader_feature_local _REQUIRE_UV2 #pragma multi_compile_instancing #pragma instancing_options procedural:vertInstancingSetup @@ -125,8 +125,8 @@ Shader "Particles/Standard Surface" CGPROGRAM #pragma target 3.0 - #pragma shader_feature _ _ALPHATEST_ON - #pragma shader_feature _REQUIRE_UV2 + #pragma shader_feature_local _ALPHATEST_ON + #pragma shader_feature_local _REQUIRE_UV2 #pragma multi_compile_instancing #pragma instancing_options procedural:vertInstancingSetup @@ -144,13 +144,13 @@ Shader "Particles/Standard Surface" #pragma instancing_options procedural:vertInstancingSetup #pragma target 3.0 - #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON _ALPHAMODULATE_ON - #pragma shader_feature _METALLICGLOSSMAP + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON _ALPHAMODULATE_ON + #pragma shader_feature_local _METALLICGLOSSMAP #pragma shader_feature _NORMALMAP #pragma shader_feature _EMISSION - #pragma shader_feature _FADING_ON - #pragma shader_feature _REQUIRE_UV2 - #pragma shader_feature EFFECT_BUMP + #pragma shader_feature_local _FADING_ON + #pragma shader_feature_local _REQUIRE_UV2 + #pragma shader_feature_local EFFECT_BUMP #include "UnityStandardParticles.cginc" ENDCG diff --git a/DefaultResourcesExtra/Particle Standard Unlit.shader b/DefaultResourcesExtra/Particle Standard Unlit.shader index be832a9..e808803 100644 --- a/DefaultResourcesExtra/Particle Standard Unlit.shader +++ b/DefaultResourcesExtra/Particle Standard Unlit.shader @@ -74,9 +74,9 @@ Shader "Particles/Standard Unlit" CGPROGRAM #pragma target 2.5 - #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON _ALPHAMODULATE_ON - #pragma shader_feature _ _COLOROVERLAY_ON _COLORCOLOR_ON _COLORADDSUBDIFF_ON - #pragma shader_feature _REQUIRE_UV2 + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON _ALPHAMODULATE_ON + #pragma shader_feature_local _ _COLOROVERLAY_ON _COLORCOLOR_ON _COLORADDSUBDIFF_ON + #pragma shader_feature_local _REQUIRE_UV2 #pragma multi_compile_shadowcaster #pragma multi_compile_instancing #pragma instancing_options procedural:vertInstancingSetup @@ -101,8 +101,8 @@ Shader "Particles/Standard Unlit" CGPROGRAM #pragma target 2.5 - #pragma shader_feature _ _ALPHATEST_ON - #pragma shader_feature _REQUIRE_UV2 + #pragma shader_feature_local _ALPHATEST_ON + #pragma shader_feature_local _REQUIRE_UV2 #pragma multi_compile_instancing #pragma instancing_options procedural:vertInstancingSetup @@ -126,8 +126,8 @@ Shader "Particles/Standard Unlit" CGPROGRAM #pragma target 2.5 - #pragma shader_feature _ _ALPHATEST_ON - #pragma shader_feature _REQUIRE_UV2 + #pragma shader_feature_local _ALPHATEST_ON + #pragma shader_feature_local _REQUIRE_UV2 #pragma multi_compile_instancing #pragma instancing_options procedural:vertInstancingSetup @@ -147,13 +147,13 @@ Shader "Particles/Standard Unlit" #pragma multi_compile_fog #pragma target 2.5 - #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON _ALPHAMODULATE_ON - #pragma shader_feature _ _COLOROVERLAY_ON _COLORCOLOR_ON _COLORADDSUBDIFF_ON + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON _ALPHAMODULATE_ON + #pragma shader_feature_local _ _COLOROVERLAY_ON _COLORCOLOR_ON _COLORADDSUBDIFF_ON #pragma shader_feature _NORMALMAP #pragma shader_feature _EMISSION - #pragma shader_feature _FADING_ON - #pragma shader_feature _REQUIRE_UV2 - #pragma shader_feature EFFECT_BUMP + #pragma shader_feature_local _FADING_ON + #pragma shader_feature_local _REQUIRE_UV2 + #pragma shader_feature_local EFFECT_BUMP #pragma vertex vertParticleUnlit #pragma fragment fragParticleUnlit diff --git a/DefaultResourcesExtra/Skybox-Panoramic.shader b/DefaultResourcesExtra/Skybox-Panoramic.shader index 770449e..eacc374 100644 --- a/DefaultResourcesExtra/Skybox-Panoramic.shader +++ b/DefaultResourcesExtra/Skybox-Panoramic.shader @@ -22,7 +22,7 @@ SubShader { #pragma vertex vert #pragma fragment frag #pragma target 2.0 - #pragma multi_compile __ _MAPPING_6_FRAMES_LAYOUT + #pragma multi_compile_local __ _MAPPING_6_FRAMES_LAYOUT #include "UnityCG.cginc" diff --git a/DefaultResourcesExtra/Skybox-Procedural.shader b/DefaultResourcesExtra/Skybox-Procedural.shader index ec13fe7..e03ae7d 100644 --- a/DefaultResourcesExtra/Skybox-Procedural.shader +++ b/DefaultResourcesExtra/Skybox-Procedural.shader @@ -26,7 +26,7 @@ SubShader { #include "UnityCG.cginc" #include "Lighting.cginc" - #pragma multi_compile _SUNDISK_NONE _SUNDISK_SIMPLE _SUNDISK_HIGH_QUALITY + #pragma multi_compile_local _SUNDISK_NONE _SUNDISK_SIMPLE _SUNDISK_HIGH_QUALITY uniform half _Exposure; // HDR exposure uniform half3 _GroundColor; diff --git a/DefaultResourcesExtra/Sprites-Default.shader b/DefaultResourcesExtra/Sprites-Default.shader index 77981d5..6a04937 100644 --- a/DefaultResourcesExtra/Sprites-Default.shader +++ b/DefaultResourcesExtra/Sprites-Default.shader @@ -36,7 +36,7 @@ Shader "Sprites/Default" #pragma fragment SpriteFrag #pragma target 2.0 #pragma multi_compile_instancing - #pragma multi_compile _ PIXELSNAP_ON + #pragma multi_compile_local _ PIXELSNAP_ON #pragma multi_compile _ ETC1_EXTERNAL_ALPHA #include "UnitySprites.cginc" ENDCG diff --git a/DefaultResourcesExtra/Sprites-Diffuse.shader b/DefaultResourcesExtra/Sprites-Diffuse.shader index c31c842..347fca6 100644 --- a/DefaultResourcesExtra/Sprites-Diffuse.shader +++ b/DefaultResourcesExtra/Sprites-Diffuse.shader @@ -31,7 +31,7 @@ Shader "Sprites/Diffuse" CGPROGRAM #pragma surface surf Lambert vertex:vert nofog nolightmap nodynlightmap keepalpha noinstancing - #pragma multi_compile _ PIXELSNAP_ON + #pragma multi_compile_local _ PIXELSNAP_ON #pragma multi_compile _ ETC1_EXTERNAL_ALPHA #include "UnitySprites.cginc" diff --git a/DefaultResourcesExtra/Sprites-Mask.shader b/DefaultResourcesExtra/Sprites-Mask.shader index 0afd97e..129c71c 100644 --- a/DefaultResourcesExtra/Sprites-Mask.shader +++ b/DefaultResourcesExtra/Sprites-Mask.shader @@ -34,7 +34,7 @@ Shader "Sprites/Mask" CGPROGRAM #pragma vertex vert #pragma fragment frag - #pragma multi_compile _ PIXELSNAP_ON + #pragma multi_compile_local _ PIXELSNAP_ON #pragma multi_compile _ ETC1_EXTERNAL_ALPHA #include "UnitySprites.cginc" diff --git a/DefaultResourcesExtra/Standard.shader b/DefaultResourcesExtra/Standard.shader index 5e5499b..ddb7f11 100644 --- a/DefaultResourcesExtra/Standard.shader +++ b/DefaultResourcesExtra/Standard.shader @@ -20,7 +20,7 @@ Shader "Standard" [ToggleOff] _GlossyReflections("Glossy Reflections", Float) = 1.0 _BumpScale("Scale", Float) = 1.0 - _BumpMap("Normal Map", 2D) = "bump" {} + [Normal] _BumpMap("Normal Map", 2D) = "bump" {} _Parallax ("Height Scale", Range (0.005, 0.08)) = 0.02 _ParallaxMap ("Height Map", 2D) = "black" {} @@ -35,7 +35,7 @@ Shader "Standard" _DetailAlbedoMap("Detail Albedo x2", 2D) = "grey" {} _DetailNormalMapScale("Scale", Float) = 1.0 - _DetailNormalMap("Normal Map", 2D) = "bump" {} + [Normal] _DetailNormalMap("Normal Map", 2D) = "bump" {} [Enum(UV0,0,UV1,1)] _UVSec ("UV Set for secondary textures", Float) = 0 @@ -73,14 +73,14 @@ Shader "Standard" // ------------------------------------- #pragma shader_feature _NORMALMAP - #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON #pragma shader_feature _EMISSION - #pragma shader_feature _METALLICGLOSSMAP - #pragma shader_feature ___ _DETAIL_MULX2 - #pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A - #pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF - #pragma shader_feature _ _GLOSSYREFLECTIONS_OFF - #pragma shader_feature _PARALLAXMAP + #pragma shader_feature_local _METALLICGLOSSMAP + #pragma shader_feature_local _DETAIL_MULX2 + #pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _GLOSSYREFLECTIONS_OFF + #pragma shader_feature_local _PARALLAXMAP #pragma multi_compile_fwdbase #pragma multi_compile_fog @@ -112,12 +112,12 @@ Shader "Standard" #pragma shader_feature _NORMALMAP - #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON - #pragma shader_feature _METALLICGLOSSMAP - #pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A - #pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF - #pragma shader_feature ___ _DETAIL_MULX2 - #pragma shader_feature _PARALLAXMAP + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _METALLICGLOSSMAP + #pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _DETAIL_MULX2 + #pragma shader_feature_local _PARALLAXMAP #pragma multi_compile_fwdadd_fullshadows #pragma multi_compile_fog @@ -144,10 +144,10 @@ Shader "Standard" // ------------------------------------- - #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON - #pragma shader_feature _METALLICGLOSSMAP - #pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A - #pragma shader_feature _PARALLAXMAP + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _METALLICGLOSSMAP + #pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + #pragma shader_feature_local _PARALLAXMAP #pragma multi_compile_shadowcaster #pragma multi_compile_instancing // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. @@ -175,13 +175,13 @@ Shader "Standard" // ------------------------------------- #pragma shader_feature _NORMALMAP - #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON #pragma shader_feature _EMISSION - #pragma shader_feature _METALLICGLOSSMAP - #pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A - #pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF - #pragma shader_feature ___ _DETAIL_MULX2 - #pragma shader_feature _PARALLAXMAP + #pragma shader_feature_local _METALLICGLOSSMAP + #pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _DETAIL_MULX2 + #pragma shader_feature_local _PARALLAXMAP #pragma multi_compile_prepassfinal #pragma multi_compile_instancing @@ -211,9 +211,9 @@ Shader "Standard" #pragma fragment frag_meta #pragma shader_feature _EMISSION - #pragma shader_feature _METALLICGLOSSMAP - #pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A - #pragma shader_feature ___ _DETAIL_MULX2 + #pragma shader_feature_local _METALLICGLOSSMAP + #pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + #pragma shader_feature_local _DETAIL_MULX2 #pragma shader_feature EDITOR_VISUALIZATION #include "UnityStandardMeta.cginc" @@ -240,14 +240,14 @@ Shader "Standard" #pragma target 2.0 #pragma shader_feature _NORMALMAP - #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON #pragma shader_feature _EMISSION - #pragma shader_feature _METALLICGLOSSMAP - #pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A - #pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF - #pragma shader_feature _ _GLOSSYREFLECTIONS_OFF - // SM2.0: NOT SUPPORTED shader_feature ___ _DETAIL_MULX2 - // SM2.0: NOT SUPPORTED shader_feature _PARALLAXMAP + #pragma shader_feature_local _METALLICGLOSSMAP + #pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _GLOSSYREFLECTIONS_OFF + // SM2.0: NOT SUPPORTED shader_feature_local _DETAIL_MULX2 + // SM2.0: NOT SUPPORTED shader_feature_local _PARALLAXMAP #pragma skip_variants SHADOWS_SOFT DIRLIGHTMAP_COMBINED @@ -275,12 +275,12 @@ Shader "Standard" #pragma target 2.0 #pragma shader_feature _NORMALMAP - #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON - #pragma shader_feature _METALLICGLOSSMAP - #pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A - #pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF - #pragma shader_feature ___ _DETAIL_MULX2 - // SM2.0: NOT SUPPORTED shader_feature _PARALLAXMAP + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _METALLICGLOSSMAP + #pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _DETAIL_MULX2 + // SM2.0: NOT SUPPORTED shader_feature_local _PARALLAXMAP #pragma skip_variants SHADOWS_SOFT #pragma multi_compile_fwdadd_fullshadows @@ -303,9 +303,9 @@ Shader "Standard" CGPROGRAM #pragma target 2.0 - #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON - #pragma shader_feature _METALLICGLOSSMAP - #pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _METALLICGLOSSMAP + #pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A #pragma skip_variants SHADOWS_SOFT #pragma multi_compile_shadowcaster @@ -332,9 +332,9 @@ Shader "Standard" #pragma fragment frag_meta #pragma shader_feature _EMISSION - #pragma shader_feature _METALLICGLOSSMAP - #pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A - #pragma shader_feature ___ _DETAIL_MULX2 + #pragma shader_feature_local _METALLICGLOSSMAP + #pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + #pragma shader_feature_local _DETAIL_MULX2 #pragma shader_feature EDITOR_VISUALIZATION #include "UnityStandardMeta.cginc" diff --git a/DefaultResourcesExtra/StandardSpecular.shader b/DefaultResourcesExtra/StandardSpecular.shader index 36b7b6b..ddbc1b6 100644 --- a/DefaultResourcesExtra/StandardSpecular.shader +++ b/DefaultResourcesExtra/StandardSpecular.shader @@ -19,7 +19,7 @@ Shader "Standard (Specular setup)" [ToggleOff] _GlossyReflections("Glossy Reflections", Float) = 1.0 _BumpScale("Scale", Float) = 1.0 - _BumpMap("Normal Map", 2D) = "bump" {} + [Normal] _BumpMap("Normal Map", 2D) = "bump" {} _Parallax ("Height Scale", Range (0.005, 0.08)) = 0.02 _ParallaxMap ("Height Map", 2D) = "black" {} @@ -34,7 +34,7 @@ Shader "Standard (Specular setup)" _DetailAlbedoMap("Detail Albedo x2", 2D) = "grey" {} _DetailNormalMapScale("Scale", Float) = 1.0 - _DetailNormalMap("Normal Map", 2D) = "bump" {} + [Normal] _DetailNormalMap("Normal Map", 2D) = "bump" {} [Enum(UV0,0,UV1,1)] _UVSec ("UV Set for secondary textures", Float) = 0 @@ -72,14 +72,14 @@ Shader "Standard (Specular setup)" // ------------------------------------- #pragma shader_feature _NORMALMAP - #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON #pragma shader_feature _EMISSION - #pragma shader_feature _SPECGLOSSMAP - #pragma shader_feature ___ _DETAIL_MULX2 - #pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A - #pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF - #pragma shader_feature _ _GLOSSYREFLECTIONS_OFF - #pragma shader_feature _PARALLAXMAP + #pragma shader_feature_local _SPECGLOSSMAP + #pragma shader_feature_local _DETAIL_MULX2 + #pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _GLOSSYREFLECTIONS_OFF + #pragma shader_feature_local _PARALLAXMAP #pragma multi_compile_fwdbase #pragma multi_compile_fog @@ -110,12 +110,12 @@ Shader "Standard (Specular setup)" // ------------------------------------- #pragma shader_feature _NORMALMAP - #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON - #pragma shader_feature _SPECGLOSSMAP - #pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A - #pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF - #pragma shader_feature ___ _DETAIL_MULX2 - #pragma shader_feature _PARALLAXMAP + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _SPECGLOSSMAP + #pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _DETAIL_MULX2 + #pragma shader_feature_local _PARALLAXMAP #pragma multi_compile_fwdadd_fullshadows #pragma multi_compile_fog @@ -142,10 +142,10 @@ Shader "Standard (Specular setup)" // ------------------------------------- - #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON - #pragma shader_feature _SPECGLOSSMAP - #pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A - #pragma shader_feature _PARALLAXMAP + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _SPECGLOSSMAP + #pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + #pragma shader_feature_local _PARALLAXMAP #pragma multi_compile_shadowcaster #pragma multi_compile_instancing // Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes. @@ -173,13 +173,13 @@ Shader "Standard (Specular setup)" // ------------------------------------- #pragma shader_feature _NORMALMAP - #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON #pragma shader_feature _EMISSION - #pragma shader_feature _SPECGLOSSMAP - #pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A - #pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF - #pragma shader_feature ___ _DETAIL_MULX2 - #pragma shader_feature _PARALLAXMAP + #pragma shader_feature_local _SPECGLOSSMAP + #pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _DETAIL_MULX2 + #pragma shader_feature_local _PARALLAXMAP #pragma multi_compile_prepassfinal #pragma multi_compile_instancing @@ -209,9 +209,9 @@ Shader "Standard (Specular setup)" #pragma fragment frag_meta #pragma shader_feature _EMISSION - #pragma shader_feature _SPECGLOSSMAP - #pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A - #pragma shader_feature ___ _DETAIL_MULX2 + #pragma shader_feature_local _SPECGLOSSMAP + #pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + #pragma shader_feature_local _DETAIL_MULX2 #pragma shader_feature EDITOR_VISUALIZATION #include "UnityStandardMeta.cginc" @@ -238,14 +238,14 @@ Shader "Standard (Specular setup)" #pragma target 2.0 #pragma shader_feature _NORMALMAP - #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON #pragma shader_feature _EMISSION - #pragma shader_feature _SPECGLOSSMAP - #pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A - #pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF - #pragma shader_feature _ _GLOSSYREFLECTIONS_OFF - #pragma shader_feature ___ _DETAIL_MULX2 - // SM2.0: NOT SUPPORTED shader_feature _PARALLAXMAP + #pragma shader_feature_local _SPECGLOSSMAP + #pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _GLOSSYREFLECTIONS_OFF + #pragma shader_feature_local _DETAIL_MULX2 + // SM2.0: NOT SUPPORTED shader_feature_local _PARALLAXMAP #pragma skip_variants SHADOWS_SOFT DYNAMICLIGHTMAP_ON DIRLIGHTMAP_COMBINED @@ -273,12 +273,12 @@ Shader "Standard (Specular setup)" #pragma target 2.0 #pragma shader_feature _NORMALMAP - #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON - #pragma shader_feature _SPECGLOSSMAP - #pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A - #pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF - #pragma shader_feature ___ _DETAIL_MULX2 - // SM2.0: NOT SUPPORTED shader_feature _PARALLAXMAP + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _SPECGLOSSMAP + #pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF + #pragma shader_feature_local _DETAIL_MULX2 + // SM2.0: NOT SUPPORTED shader_feature_local _PARALLAXMAP #pragma skip_variants SHADOWS_SOFT #pragma multi_compile_fwdadd_fullshadows @@ -301,9 +301,9 @@ Shader "Standard (Specular setup)" CGPROGRAM #pragma target 2.0 - #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON - #pragma shader_feature _SPECGLOSSMAP - #pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + #pragma shader_feature_local _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON + #pragma shader_feature_local _SPECGLOSSMAP + #pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A #pragma skip_variants SHADOWS_SOFT #pragma multi_compile_shadowcaster @@ -329,9 +329,9 @@ Shader "Standard (Specular setup)" #pragma fragment frag_meta #pragma shader_feature _EMISSION - #pragma shader_feature _SPECGLOSSMAP - #pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A - #pragma shader_feature ___ _DETAIL_MULX2 + #pragma shader_feature_local _SPECGLOSSMAP + #pragma shader_feature_local _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A + #pragma shader_feature_local _DETAIL_MULX2 #pragma shader_feature EDITOR_VISUALIZATION #include "UnityStandardMeta.cginc" diff --git a/DefaultResourcesExtra/TerrainShaders/Splats/DiffuseBaseGen.shader b/DefaultResourcesExtra/TerrainShaders/Splats/DiffuseBaseGen.shader index 0d153b0..17aa340 100644 --- a/DefaultResourcesExtra/TerrainShaders/Splats/DiffuseBaseGen.shader +++ b/DefaultResourcesExtra/TerrainShaders/Splats/DiffuseBaseGen.shader @@ -1,15 +1,9 @@ // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) -Shader "Hidden/TerrainEngine/Splatmap/Diffuse-BaseGen" { +Shader "Hidden/TerrainEngine/Splatmap/Diffuse-BaseGen" +{ Properties { - [HideInInspector] _Control("AlphaMap", 2D) = "" {} - - [HideInInspector] _Splat0 ("Layer 0 (R)", 2D) = "white" {} - [HideInInspector] _Splat1 ("Layer 1 (G)", 2D) = "white" {} - [HideInInspector] _Splat2 ("Layer 2 (B)", 2D) = "white" {} - [HideInInspector] _Splat3 ("Layer 3 (A)", 2D) = "white" {} - [HideInInspector] _DstBlend("DstBlend", Float) = 0.0 } SubShader @@ -17,7 +11,7 @@ Shader "Hidden/TerrainEngine/Splatmap/Diffuse-BaseGen" { Tags { "Name" = "_MainTex" - "Format" = "ARGB32" + "Format" = "RGBA32" "Size" = "1" } Pass diff --git a/DefaultResourcesExtra/TerrainShaders/Splats/Standard-BaseGen.shader b/DefaultResourcesExtra/TerrainShaders/Splats/Standard-BaseGen.shader index 3b1ecf5..eb01a6d 100644 --- a/DefaultResourcesExtra/TerrainShaders/Splats/Standard-BaseGen.shader +++ b/DefaultResourcesExtra/TerrainShaders/Splats/Standard-BaseGen.shader @@ -1,23 +1,9 @@ // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) -Shader "Hidden/TerrainEngine/Splatmap/Standard-BaseGen" { +Shader "Hidden/TerrainEngine/Splatmap/Standard-BaseGen" +{ Properties { - [HideInInspector] _Control("AlphaMap", 2D) = "" {} - - [HideInInspector] _Splat0 ("Layer 0 (R)", 2D) = "white" {} - [HideInInspector] _Splat1 ("Layer 1 (G)", 2D) = "white" {} - [HideInInspector] _Splat2 ("Layer 2 (B)", 2D) = "white" {} - [HideInInspector] _Splat3 ("Layer 3 (A)", 2D) = "white" {} - [HideInInspector] [Gamma] _Metallic0 ("Metallic 0", Range(0.0, 1.0)) = 0.0 - [HideInInspector] [Gamma] _Metallic1 ("Metallic 1", Range(0.0, 1.0)) = 0.0 - [HideInInspector] [Gamma] _Metallic2 ("Metallic 2", Range(0.0, 1.0)) = 0.0 - [HideInInspector] [Gamma] _Metallic3 ("Metallic 3", Range(0.0, 1.0)) = 0.0 - [HideInInspector] _Smoothness0 ("Smoothness 0", Range(0.0, 1.0)) = 1.0 - [HideInInspector] _Smoothness1 ("Smoothness 1", Range(0.0, 1.0)) = 1.0 - [HideInInspector] _Smoothness2 ("Smoothness 2", Range(0.0, 1.0)) = 1.0 - [HideInInspector] _Smoothness3 ("Smoothness 3", Range(0.0, 1.0)) = 1.0 - [HideInInspector] _DstBlend("DstBlend", Float) = 0.0 } SubShader @@ -26,12 +12,26 @@ Shader "Hidden/TerrainEngine/Splatmap/Standard-BaseGen" { #include "UnityCG.cginc" sampler2D _Control; + float4 _Control_ST; + float4 _Control_TexelSize; + + float4 _Splat0_ST; + float4 _Splat1_ST; + float4 _Splat2_ST; + float4 _Splat3_ST; - struct appdata_t { + struct appdata_t + { float4 vertex : POSITION; float2 texcoord : TEXCOORD0; }; + float2 ComputeControlUV(float2 uv) + { + // adjust splatUVs so the edges of the terrain tile lie on pixel centers + return (uv * (_Control_TexelSize.zw - 1.0f) + 0.5f) * _Control_TexelSize.xy; + } + ENDCG Pass @@ -39,7 +39,7 @@ Shader "Hidden/TerrainEngine/Splatmap/Standard-BaseGen" { Tags { "Name" = "_MainTex" - "Format" = "ARGB32" + "Format" = "RGBA32" "Size" = "1" } @@ -50,23 +50,11 @@ Shader "Hidden/TerrainEngine/Splatmap/Standard-BaseGen" { #pragma vertex vert #pragma fragment frag - sampler2D _Splat0; - sampler2D _Splat1; - sampler2D _Splat2; - sampler2D _Splat3; - - float _Smoothness0; - float _Smoothness1; - float _Smoothness2; - float _Smoothness3; + sampler2D _Splat0, _Splat1, _Splat2, _Splat3; + float _Smoothness0, _Smoothness1, _Smoothness2, _Smoothness3; - float4 _Control_TexelSize; - float4 _Splat0_ST; - float4 _Splat1_ST; - float4 _Splat2_ST; - float4 _Splat3_ST; - - struct v2f { + struct v2f + { float4 vertex : SV_POSITION; float2 texcoord0 : TEXCOORD0; float2 texcoord1 : TEXCOORD1; @@ -79,13 +67,12 @@ Shader "Hidden/TerrainEngine/Splatmap/Standard-BaseGen" { { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); - // adjust splatUVs so the edges of the terrain tile lie on pixel centers - float2 controlUV = (v.texcoord * (_Control_TexelSize.zw - 1.0f) + 0.5f) * _Control_TexelSize.xy; - o.texcoord0 = controlUV; - o.texcoord1 = TRANSFORM_TEX(v.texcoord, _Splat0); - o.texcoord2 = TRANSFORM_TEX(v.texcoord, _Splat1); - o.texcoord3 = TRANSFORM_TEX(v.texcoord, _Splat2); - o.texcoord4 = TRANSFORM_TEX(v.texcoord, _Splat3); + float2 uv = TRANSFORM_TEX(v.texcoord, _Control); + o.texcoord0 = ComputeControlUV(uv); + o.texcoord1 = TRANSFORM_TEX(uv, _Splat0); + o.texcoord2 = TRANSFORM_TEX(uv, _Splat1); + o.texcoord3 = TRANSFORM_TEX(uv, _Splat2); + o.texcoord4 = TRANSFORM_TEX(uv, _Splat3); return o; } @@ -111,6 +98,63 @@ Shader "Hidden/TerrainEngine/Splatmap/Standard-BaseGen" { ENDCG } + Pass + { + // _NormalMap pass will get ignored by terrain basemap generation code. Put here so that the VTC can use it to generate cache for normal maps. + Tags + { + "Name" = "_NormalMap" + "Format" = "A2R10G10B10" + "Size" = "1" + } + + ZTest Always Cull Off ZWrite Off + Blend One [_DstBlend] + CGPROGRAM + + #pragma vertex vert + #pragma fragment frag + + sampler2D _Normal0, _Normal1, _Normal2, _Normal3; + float _NormalScale0, _NormalScale1, _NormalScale2, _NormalScale3; + + struct v2f + { + float4 vertex : SV_POSITION; + float2 texcoord0 : TEXCOORD0; + float2 texcoord1 : TEXCOORD1; + float2 texcoord2 : TEXCOORD2; + float2 texcoord3 : TEXCOORD3; + float2 texcoord4 : TEXCOORD4; + }; + + v2f vert(appdata_t v) + { + v2f o; + o.vertex = UnityObjectToClipPos(v.vertex); + float2 uv = TRANSFORM_TEX(v.texcoord, _Control); + o.texcoord0 = ComputeControlUV(uv); + o.texcoord1 = TRANSFORM_TEX(uv, _Splat0); + o.texcoord2 = TRANSFORM_TEX(uv, _Splat1); + o.texcoord3 = TRANSFORM_TEX(uv, _Splat2); + o.texcoord4 = TRANSFORM_TEX(uv, _Splat3); + return o; + } + + float4 frag(v2f i) : SV_Target + { + float4 alpha = tex2D(_Control, i.texcoord0); + + float3 normal; + normal = UnpackNormalWithScale(tex2D(_Normal0, i.texcoord1), _NormalScale0) * alpha.x; + normal += UnpackNormalWithScale(tex2D(_Normal1, i.texcoord2), _NormalScale1) * alpha.y; + normal += UnpackNormalWithScale(tex2D(_Normal2, i.texcoord3), _NormalScale2) * alpha.z; + normal += UnpackNormalWithScale(tex2D(_Normal3, i.texcoord4), _NormalScale3) * alpha.w; + return float4(normal.xyz * 0.5f + 0.5f, 1.0f); + } + ENDCG + } + Pass { Tags @@ -118,7 +162,6 @@ Shader "Hidden/TerrainEngine/Splatmap/Standard-BaseGen" { "Name" = "_MetallicTex" "Format" = "R8" "Size" = "1/4" - "EmptyColor" = "FF000000" } ZTest Always Cull Off ZWrite Off @@ -128,12 +171,10 @@ Shader "Hidden/TerrainEngine/Splatmap/Standard-BaseGen" { #pragma vertex vert #pragma fragment frag - float _Metallic0; - float _Metallic1; - float _Metallic2; - float _Metallic3; + float _Metallic0, _Metallic1, _Metallic2, _Metallic3; - struct v2f { + struct v2f + { float4 vertex : SV_POSITION; float2 texcoord0 : TEXCOORD0; }; @@ -142,7 +183,7 @@ Shader "Hidden/TerrainEngine/Splatmap/Standard-BaseGen" { { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); - o.texcoord0 = v.texcoord; + o.texcoord0 = ComputeControlUV(TRANSFORM_TEX(v.texcoord, _Control)); return o; } diff --git a/DefaultResourcesExtra/TerrainShaders/Splats/Terrain-Utilities.shader b/DefaultResourcesExtra/TerrainShaders/Splats/Terrain-Utilities.shader index c211253..4759f3c 100644 --- a/DefaultResourcesExtra/TerrainShaders/Splats/Terrain-Utilities.shader +++ b/DefaultResourcesExtra/TerrainShaders/Splats/Terrain-Utilities.shader @@ -41,6 +41,8 @@ Shader "Hidden/Nature/Terrain/Utilities" Name "Selection" Tags { "LightMode" = "SceneSelectionPass" } + Cull Off + CGPROGRAM #pragma vertex vert #pragma fragment frag diff --git a/DefaultResourcesExtra/TerrainShaders/Trees/CameraFacingBillboardTree.shader b/DefaultResourcesExtra/TerrainShaders/Trees/CameraFacingBillboardTree.shader index 7d19cd8..6f7ab11 100644 --- a/DefaultResourcesExtra/TerrainShaders/Trees/CameraFacingBillboardTree.shader +++ b/DefaultResourcesExtra/TerrainShaders/Trees/CameraFacingBillboardTree.shader @@ -6,6 +6,7 @@ Shader "Hidden/TerrainEngine/CameraFacingBillboardTree" { _NormalTex("Base (RGB) Alpha (A)", 2D) = "white" {} _TranslucencyViewDependency("View dependency", Range(0,1)) = 0.7 _TranslucencyColor("Translucency Color", Color) = (0.73,0.85,0.41,1) + _AlphaToMask("AlphaToMask", Float) = 1.0 // On } SubShader{ Tags { @@ -14,7 +15,7 @@ Shader "Hidden/TerrainEngine/CameraFacingBillboardTree" { Pass { ColorMask rgb ZWrite On Cull Off - AlphaToMask On + AlphaToMask [_AlphaToMask] CGPROGRAM #pragma vertex vert diff --git a/DefaultResourcesExtra/TerrainShaders/Utils/CrossBlendNeighbors.shader b/DefaultResourcesExtra/TerrainShaders/Utils/CrossBlendNeighbors.shader new file mode 100644 index 0000000..8239eac --- /dev/null +++ b/DefaultResourcesExtra/TerrainShaders/Utils/CrossBlendNeighbors.shader @@ -0,0 +1,94 @@ +// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) + +Shader "Hidden/TerrainEngine/CrossBlendNeighbors" +{ + Properties + { + _TopTex ("Top Texture", any) = "black" {} + _BottomTex ("Bottom Texture", any) = "black" {} + _LeftTex ("Left Texture", any) = "black" {} + _RightTex ("Right Texture", any) = "black" {} + } + SubShader + { + Pass + { + ZTest Always Cull Off ZWrite Off + + CGPROGRAM + #pragma vertex vert + #pragma fragment CrossBlendNeighbors + #pragma target 3.0 + + #include "UnityCG.cginc" + + uniform float4 _TexCoordOffsetScale; + uniform float4 _Offsets; // bottom, top, left, right + uniform float4 _SlopeEnableFlags; // bottom, top, left, right; 0.0f - neighbor exists, 1.0f - no neighbor + uniform float _AddressMode; // 0.0f - clamp, 1.0f - mirror + + sampler2D _TopTex; + sampler2D _BottomTex; + sampler2D _LeftTex; + sampler2D _RightTex; + + struct appdata_t + { + float4 vertex : POSITION; + float2 texcoord : TEXCOORD0; + }; + + struct v2f + { + float4 vertex : SV_POSITION; + float4 texcoord : TEXCOORD0; + }; + + v2f vert (appdata_t v) + { + v2f o; + + o.vertex = UnityObjectToClipPos(v.vertex); + o.texcoord.xy = v.texcoord; + o.texcoord.zw = (v.texcoord + _TexCoordOffsetScale.xy) * _TexCoordOffsetScale.zw; + return o; + } + + float4 CrossBlendNeighbors(v2f i) : SV_Target + { + // All slope offset data is static, but we calculate it on GPU because we don't want to access height data on CPU + float2 topSlope = float2(UnpackHeightmap(tex2Dlod(_LeftTex, float4(1.0f, 1.0f, 0.0f, 0.0f))), UnpackHeightmap(tex2Dlod(_RightTex, float4(0.0f, 1.0f, 0.0f, 0.0f)))) + _Offsets.zw; + float2 bottomSlope = float2(UnpackHeightmap(tex2Dlod(_LeftTex, float4(1.0f, 0.0f, 0.0f, 0.0f))), UnpackHeightmap(tex2Dlod(_RightTex, float4(0.0f, 0.0f, 0.0f, 0.0f)))) + _Offsets.zw; + float2 leftSlope = float2(UnpackHeightmap(tex2Dlod(_BottomTex, float4(0.0f, 1.0f, 0.0f, 0.0f))), UnpackHeightmap(tex2Dlod(_TopTex, float4(0.0f, 0.0f, 0.0f, 0.0f)))) + _Offsets.xy; + float2 rightSlope = float2(UnpackHeightmap(tex2Dlod(_BottomTex, float4(1.0f, 1.0f, 0.0f, 0.0f))), UnpackHeightmap(tex2Dlod(_TopTex, float4(1.0f, 0.0f, 0.0f, 0.0f)))) + _Offsets.xy; + float2 topSlopeOffset = _Offsets.y + _SlopeEnableFlags.y * topSlope; + float2 bottomSlopeOffset = _Offsets.x + _SlopeEnableFlags.x * bottomSlope; + float2 leftSlopeOffset = _Offsets.z + _SlopeEnableFlags.z * leftSlope; + float2 rightSlopeOffset = _Offsets.w + _SlopeEnableFlags.w * rightSlope; + + float2 blendPos = saturate(i.texcoord.zw); + + float4 weights = 1.0f / max(float4(1.0f - blendPos.y, blendPos.y, blendPos.x, 1.0f - blendPos.x), 0.0000001f); + weights /= dot(weights, 1.0f); + + float4 heights = float4( + UnpackHeightmap(tex2D(_TopTex, float2(i.texcoord.x, (1.0f - i.texcoord.y) * _AddressMode.x))), + UnpackHeightmap(tex2D(_BottomTex, float2(i.texcoord.x, 1.0f - i.texcoord.y * _AddressMode.x))), + UnpackHeightmap(tex2D(_LeftTex, float2( 1.0f - i.texcoord.x * _AddressMode.x, i.texcoord.y))), + UnpackHeightmap(tex2D(_RightTex, float2((1.0f - i.texcoord.x) * _AddressMode.x, i.texcoord.y))) + ); + + heights += float4( + lerp(topSlopeOffset.x, topSlopeOffset.y, blendPos.x), + lerp(bottomSlopeOffset.x, bottomSlopeOffset.y, blendPos.x), + lerp(leftSlopeOffset.x, leftSlopeOffset.y, blendPos.y), + lerp(rightSlopeOffset.x, rightSlopeOffset.y, blendPos.y) + ); + + return PackHeightmap(dot(heights, weights)); + } + ENDCG + } + } + Fallback Off +} diff --git a/DefaultResourcesExtra/TerrainShaders/Utils/PaintHeight.shader b/DefaultResourcesExtra/TerrainShaders/Utils/PaintHeight.shader index faa713f..efa26a7 100644 --- a/DefaultResourcesExtra/TerrainShaders/Utils/PaintHeight.shader +++ b/DefaultResourcesExtra/TerrainShaders/Utils/PaintHeight.shader @@ -1,6 +1,6 @@ // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) -Shader "Hidden/TerrainEngine/PaintHeight" { + Shader "Hidden/TerrainEngine/PaintHeight" { Properties { _MainTex ("Texture", any) = "" {} } @@ -162,7 +162,7 @@ Shader "Hidden/TerrainEngine/PaintHeight" { // see https://www.desmos.com/calculator/880ka3lfkl float p = saturate(brushStrength); float w = (1.0f - p) / (p + 0.000001f); - // float w = (1.0f - p*p) / (p + 0.000001f); // alternative TODO test and compare +// float w = (1.0f - p*p) / (p + 0.000001f); // alternative TODO test and compare float fx = clamp(w * deltaHeight, -1.0f, 1.0f); float g = fx * (0.5f * fx * sign(fx) - 1.0f); @@ -184,6 +184,8 @@ Shader "Hidden/TerrainEngine/PaintHeight" { #pragma vertex vert #pragma fragment SmoothHeight + float4 _SmoothWeights; // centered, min, max, unused + float4 SmoothHeight(v2f i) : SV_Target { float2 brushUV = PaintContextUVToBrushUV(i.pcUV); @@ -211,6 +213,8 @@ Shader "Hidden/TerrainEngine/PaintHeight" { h += UnpackHeightmap(tex2D(_MainTex, heightmapUV + float2( 0, -yoffset))); h /= 8.0F; + float3 new_height = float3(h, min(h, height), max(h, height)); + h = dot(new_height, _SmoothWeights.xyz); return PackHeightmap(lerp(height, h, brushStrength)); } ENDCG @@ -241,5 +245,4 @@ Shader "Hidden/TerrainEngine/PaintHeight" { } Fallback Off - } diff --git a/DefaultResourcesExtra/UI/UI-CompositeOverdraw.shader b/DefaultResourcesExtra/UI/UI-CompositeOverdraw.shader index 1b7935e..d543edf 100644 --- a/DefaultResourcesExtra/UI/UI-CompositeOverdraw.shader +++ b/DefaultResourcesExtra/UI/UI-CompositeOverdraw.shader @@ -9,7 +9,7 @@ Shader "Hidden/UI/CompositeOverdraw" SubShader { - Tags { "ForceSupported" = "True" "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } // No culling or depth Cull Off ZWrite Off ZTest Always Blend SrcAlpha OneMinusSrcAlpha Fog { Mode off } diff --git a/DefaultResourcesExtra/UI/UI-Default.shader b/DefaultResourcesExtra/UI/UI-Default.shader index 95845fc..4f49d32 100644 --- a/DefaultResourcesExtra/UI/UI-Default.shader +++ b/DefaultResourcesExtra/UI/UI-Default.shader @@ -56,8 +56,8 @@ Shader "UI/Default" #include "UnityCG.cginc" #include "UnityUI.cginc" - #pragma multi_compile __ UNITY_UI_CLIP_RECT - #pragma multi_compile __ UNITY_UI_ALPHACLIP + #pragma multi_compile_local _ UNITY_UI_CLIP_RECT + #pragma multi_compile_local _ UNITY_UI_ALPHACLIP struct appdata_t { diff --git a/DefaultResourcesExtra/UI/UI-DefaultETC1.shader b/DefaultResourcesExtra/UI/UI-DefaultETC1.shader index d8b0b6b..9eb061b 100644 --- a/DefaultResourcesExtra/UI/UI-DefaultETC1.shader +++ b/DefaultResourcesExtra/UI/UI-DefaultETC1.shader @@ -57,8 +57,8 @@ Shader "UI/DefaultETC1" #include "UnityCG.cginc" #include "UnityUI.cginc" - #pragma multi_compile __ UNITY_UI_CLIP_RECT - #pragma multi_compile __ UNITY_UI_ALPHACLIP + #pragma multi_compile_local _ UNITY_UI_CLIP_RECT + #pragma multi_compile_local _ UNITY_UI_ALPHACLIP struct appdata_t { diff --git a/DefaultResourcesExtra/UI/UI-Lit-Bumped.shader b/DefaultResourcesExtra/UI/UI-Lit-Bumped.shader index 56710ec..2909652 100644 --- a/DefaultResourcesExtra/UI/UI-Lit-Bumped.shader +++ b/DefaultResourcesExtra/UI/UI-Lit-Bumped.shader @@ -55,8 +55,8 @@ Shader "UI/Lit/Bumped" #include "UnityCG.cginc" #include "UnityUI.cginc" - #pragma multi_compile __ UNITY_UI_CLIP_RECT - #pragma multi_compile __ UNITY_UI_ALPHACLIP + #pragma multi_compile_local _ UNITY_UI_CLIP_RECT + #pragma multi_compile_local _ UNITY_UI_ALPHACLIP struct appdata_t { diff --git a/DefaultResourcesExtra/UI/UI-Lit-Detail.shader b/DefaultResourcesExtra/UI/UI-Lit-Detail.shader index 3ce5fed..a372418 100644 --- a/DefaultResourcesExtra/UI/UI-Lit-Detail.shader +++ b/DefaultResourcesExtra/UI/UI-Lit-Detail.shader @@ -58,8 +58,8 @@ Shader "UI/Lit/Detail" #include "UnityCG.cginc" #include "UnityUI.cginc" - #pragma multi_compile __ UNITY_UI_CLIP_RECT - #pragma multi_compile __ UNITY_UI_ALPHACLIP + #pragma multi_compile_local _ UNITY_UI_CLIP_RECT + #pragma multi_compile_local _ UNITY_UI_ALPHACLIP struct appdata_t { diff --git a/DefaultResourcesExtra/UI/UI-Lit-Refraction.shader b/DefaultResourcesExtra/UI/UI-Lit-Refraction.shader index de56225..48a5256 100644 --- a/DefaultResourcesExtra/UI/UI-Lit-Refraction.shader +++ b/DefaultResourcesExtra/UI/UI-Lit-Refraction.shader @@ -64,8 +64,8 @@ Shader "UI/Lit/Refraction" #include "UnityCG.cginc" #include "UnityUI.cginc" - #pragma multi_compile __ UNITY_UI_CLIP_RECT - #pragma multi_compile __ UNITY_UI_ALPHACLIP + #pragma multi_compile_local _ UNITY_UI_CLIP_RECT + #pragma multi_compile_local _ UNITY_UI_ALPHACLIP struct appdata_t { diff --git a/DefaultResourcesExtra/UI/UI-Lit-RefractionDetail.shader b/DefaultResourcesExtra/UI/UI-Lit-RefractionDetail.shader index f1a9b94..0c029d3 100644 --- a/DefaultResourcesExtra/UI/UI-Lit-RefractionDetail.shader +++ b/DefaultResourcesExtra/UI/UI-Lit-RefractionDetail.shader @@ -68,8 +68,8 @@ Shader "UI/Lit/Refraction Detail" #include "UnityCG.cginc" #include "UnityUI.cginc" - #pragma multi_compile __ UNITY_UI_CLIP_RECT - #pragma multi_compile __ UNITY_UI_ALPHACLIP + #pragma multi_compile_local _ UNITY_UI_CLIP_RECT + #pragma multi_compile_local _ UNITY_UI_ALPHACLIP struct appdata_t { diff --git a/DefaultResourcesExtra/UI/UI-Lit-Transparent.shader b/DefaultResourcesExtra/UI/UI-Lit-Transparent.shader index c3a9abd..74c969e 100644 --- a/DefaultResourcesExtra/UI/UI-Lit-Transparent.shader +++ b/DefaultResourcesExtra/UI/UI-Lit-Transparent.shader @@ -54,8 +54,8 @@ Shader "UI/Lit/Transparent" #include "UnityCG.cginc" #include "UnityUI.cginc" - #pragma multi_compile __ UNITY_UI_CLIP_RECT - #pragma multi_compile __ UNITY_UI_ALPHACLIP + #pragma multi_compile_local _ UNITY_UI_CLIP_RECT + #pragma multi_compile_local _ UNITY_UI_ALPHACLIP struct appdata_t { diff --git a/DefaultResourcesExtra/UI/UI-Overdraw.shader b/DefaultResourcesExtra/UI/UI-Overdraw.shader index 9b0152e..59b4306 100644 --- a/DefaultResourcesExtra/UI/UI-Overdraw.shader +++ b/DefaultResourcesExtra/UI/UI-Overdraw.shader @@ -56,8 +56,8 @@ Shader "Hidden/UI/Overdraw" #include "UnityCG.cginc" #include "UnityUI.cginc" - #pragma multi_compile __ UNITY_UI_CLIP_RECT - #pragma multi_compile __ UNITY_UI_ALPHACLIP + #pragma multi_compile_local _ UNITY_UI_CLIP_RECT + #pragma multi_compile_local _ UNITY_UI_ALPHACLIP struct appdata_t { diff --git a/DefaultResourcesExtra/UI/UI-Unlit-Detail.shader b/DefaultResourcesExtra/UI/UI-Unlit-Detail.shader index 03c67d3..03ffb1e 100644 --- a/DefaultResourcesExtra/UI/UI-Unlit-Detail.shader +++ b/DefaultResourcesExtra/UI/UI-Unlit-Detail.shader @@ -58,8 +58,8 @@ Shader "UI/Unlit/Detail" #include "UnityCG.cginc" #include "UnityUI.cginc" - #pragma multi_compile __ UNITY_UI_CLIP_RECT - #pragma multi_compile __ UNITY_UI_ALPHACLIP + #pragma multi_compile_local _ UNITY_UI_CLIP_RECT + #pragma multi_compile_local _ UNITY_UI_ALPHACLIP struct appdata_t { diff --git a/DefaultResourcesExtra/VR/Shaders/BlitFromTex2DToTexArraySlice.shader b/DefaultResourcesExtra/VR/Shaders/BlitFromTex2DToTexArraySlice.shader new file mode 100644 index 0000000..0a3f762 --- /dev/null +++ b/DefaultResourcesExtra/VR/Shaders/BlitFromTex2DToTexArraySlice.shader @@ -0,0 +1,121 @@ +// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) + +Shader "Hidden/VR/BlitFromTex2DToTexArraySlice" +{ + Properties { _MainTex ("Texture", 2D) = "" {} } + SubShader + { + Pass + { + ZTest Always Cull Off ZWrite Off + + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma target 3.5 + #pragma exclude_renderers vulkan metal + + #include "UnityCG.cginc" + + UNITY_DECLARE_TEX2D(_MainTex); + uniform float4 _MainTex_ST; + uniform float _ArraySliceIndex; + + struct appdata_t { + float4 vertex : POSITION; + float2 texcoord : TEXCOORD0; + }; + + struct v2f { + float4 vertex : SV_POSITION; + float2 texcoord : TEXCOORD0; + uint slice : SV_RenderTargetArrayIndex; + }; + + v2f vert (appdata_t v) + { + v2f o; + o.vertex = UnityObjectToClipPos(v.vertex); + o.texcoord = TRANSFORM_TEX(v.texcoord.xy, _MainTex); + o.slice = _ArraySliceIndex; + return o; + } + + fixed4 frag (v2f i) : SV_Target + { + return UNITY_SAMPLE_TEX2D(_MainTex, i.texcoord.xy); + } + ENDCG + } + + Pass + { + ZTest Always Cull Off ZWrite Off + + CGPROGRAM + #pragma vertex vert + #pragma geometry geom + #pragma fragment frag + #pragma target 4.0 + + #include "UnityCG.cginc" + + UNITY_DECLARE_TEX2D(_MainTex); + uniform float4 _MainTex_ST; + uniform float _ArraySliceIndex; + + struct appdata_t { + float4 vertex : POSITION; + float2 texcoord : TEXCOORD0; + }; + + struct v2g { + float4 vertex : SV_POSITION; + float2 texcoord : TEXCOORD0; + }; + + v2g vert (appdata_t v) + { + v2g o; + o.vertex = UnityObjectToClipPos(v.vertex); + o.texcoord = TRANSFORM_TEX(v.texcoord.xy, _MainTex); + return o; + } + + struct g2f { + float4 vertex : SV_POSITION; + float2 texcoord : TEXCOORD0; + uint slice : SV_RenderTargetArrayIndex; + }; + + [maxvertexcount(3)] + void geom(triangle v2g i[3], inout TriangleStream triangleStream) + { + g2f o; + + o.slice = _ArraySliceIndex; + + o.vertex = i[0].vertex; + o.texcoord = i[0].texcoord; + triangleStream.Append(o); + + o.vertex = i[1].vertex; + o.texcoord = i[1].texcoord; + triangleStream.Append(o); + + o.vertex = i[2].vertex; + o.texcoord = i[2].texcoord; + triangleStream.Append(o); + + triangleStream.RestartStrip(); + } + + fixed4 frag (g2f i) : SV_Target + { + return UNITY_SAMPLE_TEX2D(_MainTex, i.texcoord.xy); + } + ENDCG + } + } + Fallback Off +} diff --git a/DefaultResourcesExtra/VR/Shaders/SpatialMappingWireframe.shader b/DefaultResourcesExtra/VR/Shaders/SpatialMappingWireframe.shader index 2225e90..b74b50b 100644 --- a/DefaultResourcesExtra/VR/Shaders/SpatialMappingWireframe.shader +++ b/DefaultResourcesExtra/VR/Shaders/SpatialMappingWireframe.shader @@ -37,7 +37,7 @@ Shader "VR/SpatialMapping/Wireframe" { float4 projectionSpaceVertex : SV_POSITION; float4 worldSpacePosition : TEXCOORD1; - UNITY_VERTEX_OUTPUT_STEREO + UNITY_VERTEX_OUTPUT_STEREO_EYE_INDEX }; struct g2f @@ -52,7 +52,8 @@ Shader "VR/SpatialMapping/Wireframe" { v2g o; UNITY_SETUP_INSTANCE_ID(v); - UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + UNITY_INITIALIZE_OUTPUT_STEREO_EYE_INDEX(o); + o.projectionSpaceVertex = UnityObjectToClipPos(v.vertex); o.worldSpacePosition = mul(unity_ObjectToWorld, v.vertex); return o; @@ -61,6 +62,8 @@ Shader "VR/SpatialMapping/Wireframe" [maxvertexcount(3)] void geom(triangle v2g i[3], inout TriangleStream triangleStream) { + UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i[0]); + float2 p0 = i[0].projectionSpaceVertex.xy / i[0].projectionSpaceVertex.w; float2 p1 = i[1].projectionSpaceVertex.xy / i[1].projectionSpaceVertex.w; float2 p2 = i[2].projectionSpaceVertex.xy / i[2].projectionSpaceVertex.w; @@ -79,26 +82,23 @@ Shader "VR/SpatialMapping/Wireframe" float wireThickness = 800 - _WireThickness; g2f o; - + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); o.worldSpacePosition = i[0].worldSpacePosition; o.projectionSpaceVertex = i[0].projectionSpaceVertex; o.dist.xyz = float3( (area / length(edge0)), 0.0, 0.0) * o.projectionSpaceVertex.w * wireThickness; o.dist.w = 1.0 / o.projectionSpaceVertex.w; - UNITY_TRANSFER_VERTEX_OUTPUT_STEREO(i[0], o); triangleStream.Append(o); o.worldSpacePosition = i[1].worldSpacePosition; o.projectionSpaceVertex = i[1].projectionSpaceVertex; o.dist.xyz = float3(0.0, (area / length(edge1)), 0.0) * o.projectionSpaceVertex.w * wireThickness; o.dist.w = 1.0 / o.projectionSpaceVertex.w; - UNITY_TRANSFER_VERTEX_OUTPUT_STEREO(i[1], o); triangleStream.Append(o); o.worldSpacePosition = i[2].worldSpacePosition; o.projectionSpaceVertex = i[2].projectionSpaceVertex; o.dist.xyz = float3(0.0, 0.0, (area / length(edge2))) * o.projectionSpaceVertex.w * wireThickness; o.dist.w = 1.0 / o.projectionSpaceVertex.w; - UNITY_TRANSFER_VERTEX_OUTPUT_STEREO(i[2], o); triangleStream.Append(o); } diff --git a/DefaultResourcesExtra/VideoComposite.shader b/DefaultResourcesExtra/VideoComposite.shader new file mode 100644 index 0000000..ec43641 --- /dev/null +++ b/DefaultResourcesExtra/VideoComposite.shader @@ -0,0 +1,65 @@ +// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) + +Shader "Hidden/VideoComposite" +{ + Properties + { + _MainTex ("_MainTex (A)", 2D) = "black" + } + + CGINCLUDE + + #include "UnityCG.cginc" + + sampler2D _MainTex; + float _AlphaParam; + float4 _RightEyeUVOffset; + float4 _MainTex_ST; + + struct appdata_t { + float4 vertex : POSITION; + float2 texcoord : TEXCOORD0; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 vertex : SV_POSITION; + float2 texcoord : TEXCOORD0; + UNITY_VERTEX_OUTPUT_STEREO + }; + + v2f vertexDirect(appdata_t v) + { + v2f o; + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + o.vertex = UnityObjectToClipPos(v.vertex); + o.texcoord = TRANSFORM_TEX(v.texcoord.xy, _MainTex) + unity_StereoEyeIndex * _RightEyeUVOffset.xy; + return o; + } + + fixed4 fragmentBlit(v2f i) : SV_Target + { + fixed4 col = tex2D(_MainTex, i.texcoord); + return fixed4(col.rgb, col.a * _AlphaParam); + } + + ENDCG + + SubShader + { + Tags{ "Queue" = "Transparent" } + + Pass + { + Name "Default" + Cull Off ZWrite On Blend SrcAlpha OneMinusSrcAlpha + CGPROGRAM + #pragma vertex vertexDirect + #pragma fragment fragmentBlit + ENDCG + } + } + + FallBack Off +} diff --git a/DefaultResourcesExtra/VideoDecode.shader b/DefaultResourcesExtra/VideoDecode.shader index c4161ab..1c52322 100644 --- a/DefaultResourcesExtra/VideoDecode.shader +++ b/DefaultResourcesExtra/VideoDecode.shader @@ -16,8 +16,6 @@ Shader "Hidden/VideoDecode" sampler2D _MainTex; sampler2D _SecondTex; sampler2D _ThirdTex; - float _AlphaParam; - float4 _RightEyeUVOffset; float4 _MainTex_TexelSize; float4 _MainTex_ST; @@ -44,7 +42,7 @@ Shader "Hidden/VideoDecode" { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); - o.texcoord = TRANSFORM_TEX(v.texcoord.xy, _MainTex) + unity_StereoEyeIndex * _RightEyeUVOffset.xy; + o.texcoord = TRANSFORM_TEX(v.texcoord.xy, _MainTex); return o; } @@ -128,6 +126,49 @@ Shader "Hidden/VideoDecode" return AdjustForColorSpace(result); } + fixed4 fragmentP010RGBOne(v2f i) : SV_Target + { + float3 yCbCr = float3( tex2D(_MainTex, i.texcoord).r , + tex2D(_SecondTex, i.texcoord).r, + tex2D(_SecondTex, i.texcoord).g); + yCbCr *= 65535.0 / 1023.0; // Source data is 10 bit in a 16 bit texture so we need to scale the values so that the result covers the full range from 0 to 1 + yCbCr -= float3(0.0625, 0.5, 0.5); + + fixed4 result = fixed4( dot(float3(1.1644f, 0.0f, 1.7927f), yCbCr), + dot(float3(1.1644f, -0.2133f, -0.5329f), yCbCr), + dot(float3(1.1644f, 2.1124f, 0.0f), yCbCr), + 1.0f); + + return AdjustForColorSpace(result); + } + + fixed4 fragmentP010RGBA(v2f i) : SV_Target + { + float ty = 0.5f * i.texcoord.x; // Y : left half of luma plane + float ta = ty + 0.5f; // A : right half of luma plane + float tuv = ty; // UV : just use left half of chroma plane + + fixed y = tex2D(_MainTex, float2(ty, i.texcoord.y)).a; + fixed a = tex2D(_MainTex, float2(ta, i.texcoord.y)).a; + fixed2 uv = tex2D(_SecondTex, float2(tuv, i.texcoord.y)).rg; + fixed u = uv.r; + fixed v = uv.g; + + // Source data is 10 bit in a 16 bit texture so we need to scale the values so that the result covers the full range from 0 to 1. + y *= 65535.0 / 1023.0; + u *= 65535.0 / 1023.0; + v *= 65535.0 / 1023.0; + a *= 65535.0 / 1023.0; + + fixed y1 = 1.15625 * y; + fixed4 result = fixed4(y1 + 1.59375 * v - 0.87254, + y1 - 0.390625 * u - 0.8125 * v + 0.53137, + y1 + 1.984375 * u - 1.06862, + 1.15625 * (a - 0.062745)); + + return AdjustForColorSpace(result); + } + fixed4 fragmentRGB_FullAlpha(v2f i) : SV_Target { float2 tc = float2(0.5f * i.texcoord.x, i.texcoord.y); @@ -159,7 +200,7 @@ Shader "Hidden/VideoDecode" fixed4 fragmentSemiPRGBA(v2f i) : SV_Target { float maxX = _MainTex_TexelSize.z - 0.5f; - float z1 = 2.0f / maxX; + float z1 = 1.0f / maxX; float tc = 0.5f * i.texcoord.x; int rectx = (int)floor(tc * maxX + 0.5f); int rectux = (fmod(rectx, 2.0) == 0.0) ? rectx : (rectx - 1); @@ -190,13 +231,7 @@ Shader "Hidden/VideoDecode" fixed4 fragmentRGBANormal(v2f i) : SV_Target { fixed4 col = tex2D(_MainTex, i.texcoord); - return AdjustForColorSpace(fixed4(col.rgb, col.a * _AlphaParam)); - } - - fixed4 fragmentBlit(v2f i) : SV_Target - { - fixed4 col = tex2D(_MainTex, i.texcoord); - return fixed4(col.rgb, col.a * _AlphaParam); + return AdjustForColorSpace(col.rgba); } ENDCG @@ -238,17 +273,6 @@ Shader "Hidden/VideoDecode" // 3 Pass - { - Name "Composite_RGBA_To_RGBA" - Cull Off ZWrite On Blend SrcAlpha OneMinusSrcAlpha - CGPROGRAM - #pragma vertex vertexDirect - #pragma fragment fragmentBlit - ENDCG - } - - // 4 - Pass { Name "Flip_RGBA_To_RGBA" ZTest Always Cull Off ZWrite Off Blend Off @@ -258,7 +282,7 @@ Shader "Hidden/VideoDecode" ENDCG } - // 5 + // 4 Pass { Name "Flip_RGBASplit_To_RGBA" @@ -269,7 +293,7 @@ Shader "Hidden/VideoDecode" ENDCG } - // 6 + // 5 Pass { Name "Flip_SemiPlanarYCbCr_To_RGB1" @@ -280,7 +304,7 @@ Shader "Hidden/VideoDecode" ENDCG } - // 7 + // 6 Pass { Name "Flip_SemiPlanarYCbCrA_To_RGBA" @@ -291,7 +315,7 @@ Shader "Hidden/VideoDecode" ENDCG } - // 8 - NV12 format: Y plane (_MainTex / 8-bit) followed by interleaved U/V plane (_SecondTex / 8-bit each component) with 2x2 subsampling (so half width/height) + // 7 - NV12 format: Y plane (_MainTex / 8-bit) followed by interleaved U/V plane (_SecondTex / 8-bit each component) with 2x2 subsampling (so half width/height) Pass { Name "Flip_NV12_To_RGB1" @@ -302,7 +326,7 @@ Shader "Hidden/VideoDecode" ENDCG } - // 9 - NV12 format, split alpha: YA plane (_MainTex / 8-bit) followed by interleaved U/V plane (_SecondTex / 8-bit each component) with 2x2 subsampling (so half width/height) + // 8 - NV12 format, split alpha: YA plane (_MainTex / 8-bit) followed by interleaved U/V plane (_SecondTex / 8-bit each component) with 2x2 subsampling (so half width/height) Pass { Name "Flip_NV12_To_RGBA" @@ -312,6 +336,29 @@ Shader "Hidden/VideoDecode" #pragma fragment fragmentNV12RGBA ENDCG } + + // 9 - P010 format: Y plane (_MainTex / 10-bit) followed by interleaved U/V plane (_SecondTex / 10-bit each component) with 2x2 subsampling (so half width/height), the shader scales the 10 bit source data to 16 bit output. + Pass + { + Name "Flip_P010_To_RGB1" + ZTest Always Cull Off ZWrite Off Blend Off + CGPROGRAM + #pragma vertex vertexFlip + #pragma fragment fragmentP010RGBOne + ENDCG + } + + // 10 - P010 format, split alpha: YA plane (_MainTex / 10-bit) followed by interleaved U/V plane (_SecondTex / 10-bit each component) with 2x2 subsampling (so half width/height), the shader scales the 10 bit source data to 16 bit output. + Pass + { + Name "Flip_P010_To_RGBA" + ZTest Always Cull Off ZWrite Off Blend Off + CGPROGRAM + #pragma vertex vertexFlip + #pragma fragment fragmentNV12RGBA + ENDCG + } + } FallBack Off diff --git a/DefaultResourcesExtra/VideoDecodeML.shader b/DefaultResourcesExtra/VideoDecodeML.shader new file mode 100644 index 0000000..8c86eea --- /dev/null +++ b/DefaultResourcesExtra/VideoDecodeML.shader @@ -0,0 +1,112 @@ +// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) + +Shader "Hidden/VideoDecodeML" +{ +GLSLINCLUDE + #include "UnityCG.glslinc" +ENDGLSL + + SubShader + { + Pass + { + Name "RGBAExternal_To_RGBA" + ZTest Always Cull Off ZWrite Off Blend Off + + GLSLPROGRAM + + #extension GL_OES_EGL_image_external : require + #pragma glsl_es2 + + uniform vec4 _MainTex_ST; + + #ifdef VERTEX + + varying vec2 textureCoord; + void main() + { + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; + textureCoord = TRANSFORM_TEX_ST(gl_MultiTexCoord0, _MainTex_ST); + // Video texture from the ML Api comes in upside down, we need to flip it vertically for correct orientation + textureCoord.y = 1.0 - textureCoord.y; + } + + #endif + + #ifdef FRAGMENT + + vec4 AdjustForColorSpace(vec4 color) + { + #ifdef UNITY_COLORSPACE_GAMMA + return color; + #else + // Approximate version from http://chilliant.blogspot.com.au/2012/08/srgb-approximations-for-hlsl.html?m=1 + vec3 sRGB = color.rgb; + return vec4(sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878), color.a); + #endif + } + + varying vec2 textureCoord; + uniform samplerExternalOES _MainTex; + void main() + { + gl_FragColor = AdjustForColorSpace(textureExternal(_MainTex, textureCoord)); + } + + #endif + + ENDGLSL + } + + Pass + { + Name "RGBASplitExternal_To_RGBA" + ZTest Always Cull Off ZWrite Off Blend Off + + GLSLPROGRAM + + #extension GL_OES_EGL_image_external : require + #pragma glsl_es2 + uniform vec4 _MainTex_ST; + + #ifdef VERTEX + + varying vec3 textureCoordSplit; + void main() + { + gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; + textureCoordSplit.xz = vec2(0.5 * gl_MultiTexCoord0.x * _MainTex_ST.x, gl_MultiTexCoord0.y * _MainTex_ST.y) + _MainTex_ST.zw; + textureCoordSplit.y = textureCoordSplit.x + 0.5 * _MainTex_ST.x; + } + + #endif + + #ifdef FRAGMENT + + vec4 AdjustForColorSpace(vec4 color) + { + #ifdef UNITY_COLORSPACE_GAMMA + return color; + #else + // Approximate version from http://chilliant.blogspot.com.au/2012/08/srgb-approximations-for-hlsl.html?m=1 + vec3 sRGB = color.rgb; + return vec4(sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878), color.a); + #endif + } + + varying vec3 textureCoordSplit; + uniform samplerExternalOES _MainTex; + void main() + { + gl_FragColor.rgb = AdjustForColorSpace(textureExternal(_MainTex, textureCoordSplit.xz)).rgb; + gl_FragColor.a = textureExternal(_MainTex, textureCoordSplit.yz).g; + } + + #endif + + ENDGLSL + } + } + + FallBack Off +} diff --git a/Editor/StandardShaderGUI.cs b/Editor/StandardShaderGUI.cs index 7b70d3f..ba1078c 100644 --- a/Editor/StandardShaderGUI.cs +++ b/Editor/StandardShaderGUI.cs @@ -2,6 +2,7 @@ using System; using UnityEngine; +using TargetAttributes = UnityEditor.BuildTargetDiscovery.TargetAttributes; namespace UnityEditor { @@ -260,7 +261,8 @@ void BlendModePopup() void DoNormalArea() { m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapText, bumpMap, bumpMap.textureValue != null ? bumpScale : null); - if (bumpScale.floatValue != 1 && UnityEditorInternal.InternalEditorUtility.IsMobilePlatform(EditorUserBuildSettings.activeBuildTarget)) + if (bumpScale.floatValue != 1 + && BuildTargetDiscovery.PlatformHasFlag(EditorUserBuildSettings.activeBuildTarget, TargetAttributes.HasIntegratedGPU)) if (m_MaterialEditor.HelpBoxWithButton( EditorGUIUtility.TrTextContent("Bump scale is not supported on mobile platforms"), EditorGUIUtility.TrTextContent("Fix Now"))) diff --git a/README.md b/README.md index 9dd817d..aaea000 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Unity Built in Shaders -Current repository version: 2018.3.13f1 +Current repository version: 2019.1.0f2 An unofficial repo for Unity Built-in Shaders.