├── .github └── FUNDING.yml ├── .gitignore ├── Data └── Definitions.db ├── LICENSE ├── Library ├── BuiltinShaders │ ├── CGIncludes │ │ ├── AutoLight.html │ │ ├── GLSLSupport.html │ │ ├── HLSLSupport.html │ │ ├── Lighting.html │ │ ├── SpeedTree8Common.html │ │ ├── SpeedTreeBillboardCommon.html │ │ ├── TerrainPreview.html │ │ ├── TerrainTool.html │ │ ├── Tessellation.html │ │ ├── UnityCG.html │ │ ├── UnityDeferredLibrary.html │ │ ├── UnityDeprecated.html │ │ ├── UnityGBuffer.html │ │ ├── UnityGlobalIllumination.html │ │ ├── UnityImageBasedLighting.html │ │ ├── UnityInstancing.html │ │ ├── UnityLightingCommon.html │ │ ├── UnityMetaPass.html │ │ ├── UnityPBSLighting.html │ │ ├── UnityShaderUtilities.html │ │ ├── UnityShaderVariables.html │ │ ├── UnityShadowLibrary.html │ │ ├── UnitySprites.html │ │ ├── UnityStandardBRDF.html │ │ ├── UnityStandardConfig.html │ │ ├── UnityStandardCore.html │ │ ├── UnityStandardCoreForward.html │ │ ├── UnityStandardCoreForwardSimple.html │ │ ├── UnityStandardInput.html │ │ ├── UnityStandardMeta.html │ │ └── UnityStandardUtils.html │ ├── DefaultResources │ │ ├── Font.html │ │ ├── Internal-Colored.html │ │ ├── Internal-ErrorShader.html │ │ ├── Internal-Skinning-Util.html │ │ └── PerformanceTools │ │ │ └── FrameDebuggerRenderTargetDisplay.html │ └── DefaultResourcesExtra │ │ ├── Internal-DeferredReflections.html │ │ ├── Internal-DeferredShading.html │ │ ├── Internal-DepthNormalsTexture.html │ │ ├── Internal-ScreenSpaceShadows.html │ │ ├── Particle Add.html │ │ ├── Reflect-Bumped.html │ │ ├── Reflect-Diffuse.html │ │ ├── Reflect-Glossy.html │ │ ├── Reflect-Parallax.html │ │ ├── Reflect-ParallaxSpec.html │ │ ├── Reflect-VertexLit.html │ │ ├── Skybox-Cubed.html │ │ ├── Skybox-Panoramic.html │ │ ├── Skybox-Procedural.html │ │ ├── Skybox.html │ │ ├── Sprites-Default.html │ │ ├── Sprites-Diffuse.html │ │ ├── Sprites-Mask.html │ │ ├── Standard.html │ │ ├── StandardSpecular.html │ │ └── Unlit │ │ └── Unlit-Alpha.html └── PostProcessing │ ├── Builtins │ ├── Bloom.html │ ├── Copy.html │ ├── CopyStd.html │ ├── CopyStdFromDoubleWide.html │ ├── CopyStdFromTexArray.html │ ├── DeferredFog.html │ ├── DepthOField.html │ ├── DepthOfField.html │ ├── DiscardAlpha.html │ ├── DiskKernels.html │ ├── FastApproximateAntialiasing.html │ ├── FinalPass.html │ ├── Fog.html │ ├── GrainBaker.html │ ├── Lut2DBaker.html │ ├── MotionBlur.html │ ├── MultiScaleVO.html │ ├── SMAA.html │ ├── ScalableAO.html │ ├── ScreenSpaceReflections.html │ ├── SubpixelMorphologicalAntialiasing.html │ ├── SubpixelMorphologicalAntialiasingBridge.html │ ├── TemporalAntialiasing.html │ ├── Texture2DLerp.html │ └── Uber.html │ ├── Colors.html │ └── StdLib.html ├── README.md ├── Scripts ├── link_definitions.js ├── prettify.js ├── run_prettify.js ├── sql-wasm.js ├── sql-wasm.wasm ├── viewer.js └── worker.sql-wasm.js ├── Styles ├── Fonts │ ├── FontAwesome.otf │ ├── fa-brands-400.eot │ ├── fa-brands-400.svg │ ├── fa-brands-400.ttf │ ├── fa-brands-400.woff │ ├── fa-brands-400.woff2 │ ├── fontawesome-webfont.eot │ ├── fontawesome-webfont.svg │ ├── fontawesome-webfont.ttf │ ├── fontawesome-webfont.woff │ └── fontawesome-webfont.woff2 ├── Style.css ├── prettify.css └── vscode.css ├── Tools ├── DynamicViewer.html ├── Paste.html └── Viewer.html └── index.html /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | patreon: teamdogpit 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | [Ll]ibrary/ 2 | [Tt]emp/ 3 | [Oo]bj/ 4 | [Bb]uild/ 5 | [Bb]uilds/ 6 | Assets/AssetStoreTools* 7 | 8 | # Visual Studio cache directory 9 | .vs/ 10 | 11 | # Autogenerated VS/MD/Consulo solution and project files 12 | ExportedObj/ 13 | .consulo/ 14 | *.csproj 15 | *.unityproj 16 | *.sln 17 | *.suo 18 | *.tmp 19 | *.user 20 | *.userprefs 21 | *.pidb 22 | *.booproj 23 | *.svd 24 | *.pdb 25 | *.opendb 26 | 27 | # Unity3D generated meta files 28 | *.pidb.meta 29 | *.pdb.meta 30 | 31 | # Unity3D Generated File On Crash Reports 32 | sysinfo.txt 33 | 34 | # Builds 35 | *.apk 36 | *.unitypackage 37 | -------------------------------------------------------------------------------- /Data/Definitions.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xibanya/UnityShaderViewer/4572f325f73a5052cf7ed45c2c03d126b35ebb91/Data/Definitions.db -------------------------------------------------------------------------------- /Library/BuiltinShaders/CGIncludes/GLSLSupport.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |5 | // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) 6 | 7 | #ifndef GLSL_SUPPORT_INCLUDED 8 | #define GLSL_SUPPORT_INCLUDED 9 | 10 | // Automatically included in raw GLSL (GLSLPROGRAM) shader snippets, to map from some of the legacy OpenGL 11 | // variable names to uniform names used by Unity. 12 | 13 | #ifdef GL_FRAGMENT_PRECISION_HIGH 14 | precision highp float; 15 | #else 16 | precision mediump float; 17 | #endif 18 | 19 | uniform mat4 unity_ObjectToWorld; 20 | uniform mat4 unity_WorldToObject; 21 | uniform mat4 unity_MatrixVP; 22 | uniform mat4 unity_MatrixV; 23 | uniform mat4 unity_MatrixInvV; 24 | uniform mat4 glstate_matrix_projection; 25 | 26 | #define gl_ModelViewProjectionMatrix (unity_MatrixVP * unity_ObjectToWorld) 27 | #define gl_ModelViewMatrix (unity_MatrixV * unity_ObjectToWorld) 28 | #define gl_ModelViewMatrixTranspose (transpose(unity_MatrixV * unity_ObjectToWorld)) 29 | #define gl_ModelViewMatrixInverseTranspose (transpose(unity_WorldToObject * unity_MatrixInvV)) 30 | #define gl_NormalMatrix (transpose(mat3(unity_WorldToObject * unity_MatrixInvV))) 31 | #define gl_ProjectionMatrix glstate_matrix_projection 32 | 33 | #if __VERSION__ < 120 34 | #ifndef UNITY_GLSL_STRIP_TRANSPOSE 35 | mat3 transpose(mat3 mtx) 36 | { 37 | vec3 c0 = mtx[0]; 38 | vec3 c1 = mtx[1]; 39 | vec3 c2 = mtx[2]; 40 | 41 | return mat3( 42 | vec3(c0.x, c1.x, c2.x), 43 | vec3(c0.y, c1.y, c2.y), 44 | vec3(c0.z, c1.z, c2.z) 45 | ); 46 | } 47 | mat4 transpose(mat4 mtx) 48 | { 49 | vec4 c0 = mtx[0]; 50 | vec4 c1 = mtx[1]; 51 | vec4 c2 = mtx[2]; 52 | vec4 c3 = mtx[3]; 53 | 54 | return mat4( 55 | vec4(c0.x, c1.x, c2.x, c3.x), 56 | vec4(c0.y, c1.y, c2.y, c3.y), 57 | vec4(c0.z, c1.z, c2.z, c3.z), 58 | vec4(c0.w, c1.w, c2.w, c3.w) 59 | ); 60 | } 61 | #endif 62 | #endif // __VERSION__ < 120 63 | 64 | #endif // GLSL_SUPPORT_INCLUDED 65 |66 | 67 | 68 | -------------------------------------------------------------------------------- /Library/BuiltinShaders/CGIncludes/Lighting.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) 6 | 7 | #ifndef LIGHTING_INCLUDED 8 | #define LIGHTING_INCLUDED 9 | 10 | #include "UnityLightingCommon.cginc" 11 | #include "UnityGBuffer.cginc" 12 | #include "UnityGlobalIllumination.cginc" 13 | 14 | struct SurfaceOutput { 15 | fixed3 Albedo; 16 | fixed3 Normal; 17 | fixed3 Emission; 18 | half Specular; 19 | fixed Gloss; 20 | fixed Alpha; 21 | }; 22 | 23 | #ifndef USING_DIRECTIONAL_LIGHT 24 | #if defined (DIRECTIONAL_COOKIE) || defined (DIRECTIONAL) 25 | #define USING_DIRECTIONAL_LIGHT 26 | #endif 27 | #endif 28 | 29 | #if defined(UNITY_SHOULD_SAMPLE_SH) || defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON) 30 | #define UNITY_LIGHT_FUNCTION_APPLY_INDIRECT 31 | #endif 32 | 33 | inline fixed4 UnityLambertLight (SurfaceOutput s, UnityLight light) 34 | { 35 | fixed diff = max (0, dot (s.Normal, light.dir)); 36 | 37 | fixed4 c; 38 | c.rgb = s.Albedo * light.color * diff; 39 | c.a = s.Alpha; 40 | return c; 41 | } 42 | 43 | inline fixed4 LightingLambert (SurfaceOutput s, UnityGI gi) 44 | { 45 | fixed4 c; 46 | c = UnityLambertLight (s, gi.light); 47 | 48 | #ifdef UNITY_LIGHT_FUNCTION_APPLY_INDIRECT 49 | c.rgb += s.Albedo * gi.indirect.diffuse; 50 | #endif 51 | 52 | return c; 53 | } 54 | 55 | inline half4 LightingLambert_Deferred (SurfaceOutput s, UnityGI gi, out half4 outGBuffer0, out half4 outGBuffer1, out half4 outGBuffer2) 56 | { 57 | UnityStandardData data; 58 | data.diffuseColor = s.Albedo; 59 | data.occlusion = 1; 60 | data.specularColor = 0; 61 | data.smoothness = 0; 62 | data.normalWorld = s.Normal; 63 | 64 | UnityStandardDataToGbuffer(data, outGBuffer0, outGBuffer1, outGBuffer2); 65 | 66 | half4 emission = half4(s.Emission, 1); 67 | 68 | #ifdef UNITY_LIGHT_FUNCTION_APPLY_INDIRECT 69 | emission.rgb += s.Albedo * gi.indirect.diffuse; 70 | #endif 71 | 72 | return emission; 73 | } 74 | 75 | inline void LightingLambert_GI ( 76 | SurfaceOutput s, 77 | UnityGIInput data, 78 | inout UnityGI gi) 79 | { 80 | gi = UnityGlobalIllumination (data, 1.0, s.Normal); 81 | } 82 | 83 | inline fixed4 LightingLambert_PrePass (SurfaceOutput s, half4 light) 84 | { 85 | fixed4 c; 86 | c.rgb = s.Albedo * light.rgb; 87 | c.a = s.Alpha; 88 | return c; 89 | } 90 | 91 | // NOTE: some intricacy in shader compiler on some GLES2.0 platforms (iOS) needs 'viewDir' & 'h' 92 | // to be mediump instead of lowp, otherwise specular highlight becomes too bright. 93 | inline fixed4 UnityBlinnPhongLight (SurfaceOutput s, half3 viewDir, UnityLight light) 94 | { 95 | half3 h = normalize (light.dir + viewDir); 96 | 97 | fixed diff = max (0, dot (s.Normal, light.dir)); 98 | 99 | float nh = max (0, dot (s.Normal, h)); 100 | float spec = pow (nh, s.Specular*128.0) * s.Gloss; 101 | 102 | fixed4 c; 103 | c.rgb = s.Albedo * light.color * diff + light.color * _SpecColor.rgb * spec; 104 | c.a = s.Alpha; 105 | 106 | return c; 107 | } 108 | 109 | inline fixed4 LightingBlinnPhong (SurfaceOutput s, half3 viewDir, UnityGI gi) 110 | { 111 | fixed4 c; 112 | c = UnityBlinnPhongLight (s, viewDir, gi.light); 113 | 114 | #ifdef UNITY_LIGHT_FUNCTION_APPLY_INDIRECT 115 | c.rgb += s.Albedo * gi.indirect.diffuse; 116 | #endif 117 | 118 | return c; 119 | } 120 | 121 | inline half4 LightingBlinnPhong_Deferred (SurfaceOutput s, half3 viewDir, UnityGI gi, out half4 outGBuffer0, out half4 outGBuffer1, out half4 outGBuffer2) 122 | { 123 | UnityStandardData data; 124 | data.diffuseColor = s.Albedo; 125 | data.occlusion = 1; 126 | // PI factor come from StandardBDRF (UnityStandardBRDF.cginc:351 for explanation) 127 | data.specularColor = _SpecColor.rgb * s.Gloss * (1/UNITY_PI); 128 | data.smoothness = s.Specular; 129 | data.normalWorld = s.Normal; 130 | 131 | UnityStandardDataToGbuffer(data, outGBuffer0, outGBuffer1, outGBuffer2); 132 | 133 | half4 emission = half4(s.Emission, 1); 134 | 135 | #ifdef UNITY_LIGHT_FUNCTION_APPLY_INDIRECT 136 | emission.rgb += s.Albedo * gi.indirect.diffuse; 137 | #endif 138 | 139 | return emission; 140 | } 141 | 142 | inline void LightingBlinnPhong_GI ( 143 | SurfaceOutput s, 144 | UnityGIInput data, 145 | inout UnityGI gi) 146 | { 147 | gi = UnityGlobalIllumination (data, 1.0, s.Normal); 148 | } 149 | 150 | inline fixed4 LightingBlinnPhong_PrePass (SurfaceOutput s, half4 light) 151 | { 152 | fixed spec = light.a * s.Gloss; 153 | 154 | fixed4 c; 155 | c.rgb = (s.Albedo * light.rgb + light.rgb * _SpecColor.rgb * spec); 156 | c.a = s.Alpha; 157 | return c; 158 | } 159 | 160 | #ifdef UNITY_CAN_COMPILE_TESSELLATION 161 | struct UnityTessellationFactors { 162 | float edge[3] : SV_TessFactor; 163 | float inside : SV_InsideTessFactor; 164 | }; 165 | #endif // UNITY_CAN_COMPILE_TESSELLATION 166 | 167 | // Deprecated, kept around for existing user shaders. 168 | #define UNITY_DIRBASIS \ 169 | const half3x3 unity_DirBasis = half3x3( \ 170 | half3( 0.81649658, 0.0, 0.57735027), \ 171 | half3(-0.40824830, 0.70710678, 0.57735027), \ 172 | half3(-0.40824830, -0.70710678, 0.57735027) \ 173 | ); 174 | 175 | // Deprecated, kept around for existing user shaders. Only sampling the flat lightmap now. 176 | half3 DirLightmapDiffuse(in half3x3 dirBasis, fixed4 color, fixed4 scale, half3 normal, bool surfFuncWritesNormal, out half3 scalePerBasisVector) 177 | { 178 | scalePerBasisVector = 1; 179 | return DecodeLightmap (color); 180 | } 181 | 182 | #endif 183 |184 | 185 | 186 | -------------------------------------------------------------------------------- /Library/BuiltinShaders/CGIncludes/SpeedTreeBillboardCommon.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) 6 | 7 | #ifndef SPEEDTREE_BILLBOARD_COMMON_INCLUDED 8 | #define SPEEDTREE_BILLBOARD_COMMON_INCLUDED 9 | 10 | #define SPEEDTREE_ALPHATEST 11 | fixed _Cutoff; 12 | 13 | #include "SpeedTreeCommon.cginc" 14 | 15 | CBUFFER_START(UnityBillboardPerCamera) 16 | float3 unity_BillboardNormal; 17 | float3 unity_BillboardTangent; 18 | float4 unity_BillboardCameraParams; 19 | #define unity_BillboardCameraPosition (unity_BillboardCameraParams.xyz) 20 | #define unity_BillboardCameraXZAngle (unity_BillboardCameraParams.w) 21 | CBUFFER_END 22 | 23 | CBUFFER_START(UnityBillboardPerBatch) 24 | float4 unity_BillboardInfo; // x: num of billboard slices; y: 1.0f / (delta angle between slices) 25 | float4 unity_BillboardSize; // x: width; y: height; z: bottom 26 | float4 unity_BillboardImageTexCoords[16]; 27 | CBUFFER_END 28 | 29 | struct SpeedTreeBillboardData 30 | { 31 | float4 vertex : POSITION; 32 | float2 texcoord : TEXCOORD0; 33 | float4 texcoord1 : TEXCOORD1; 34 | float3 normal : NORMAL; 35 | float4 tangent : TANGENT; 36 | float4 color : COLOR; 37 | UNITY_VERTEX_INPUT_INSTANCE_ID 38 | }; 39 | 40 | void SpeedTreeBillboardVert(inout SpeedTreeBillboardData IN, out Input OUT) 41 | { 42 | UNITY_INITIALIZE_OUTPUT(Input, OUT); 43 | 44 | // assume no scaling & rotation 45 | float3 worldPos = IN.vertex.xyz + float3(unity_ObjectToWorld[0].w, unity_ObjectToWorld[1].w, unity_ObjectToWorld[2].w); 46 | 47 | #ifdef BILLBOARD_FACE_CAMERA_POS 48 | float3 eyeVec = normalize(unity_BillboardCameraPosition - worldPos); 49 | float3 billboardTangent = normalize(float3(-eyeVec.z, 0, eyeVec.x)); // cross(eyeVec, {0,1,0}) 50 | float3 billboardNormal = float3(billboardTangent.z, 0, -billboardTangent.x); // cross({0,1,0},billboardTangent) 51 | float3 angle = atan2(billboardNormal.z, billboardNormal.x); // signed angle between billboardNormal to {0,0,1} 52 | angle += angle < 0 ? 2 * UNITY_PI : 0; 53 | #else 54 | float3 billboardTangent = unity_BillboardTangent; 55 | float3 billboardNormal = unity_BillboardNormal; 56 | float angle = unity_BillboardCameraXZAngle; 57 | #endif 58 | 59 | float widthScale = IN.texcoord1.x; 60 | float heightScale = IN.texcoord1.y; 61 | float rotation = IN.texcoord1.z; 62 | 63 | float2 percent = IN.texcoord.xy; 64 | float3 billboardPos = (percent.x - 0.5f) * unity_BillboardSize.x * widthScale * billboardTangent; 65 | billboardPos.y += (percent.y * unity_BillboardSize.y + unity_BillboardSize.z) * heightScale; 66 | 67 | #ifdef ENABLE_WIND 68 | if (_WindQuality * _WindEnabled > 0) 69 | billboardPos = GlobalWind(billboardPos, worldPos, true, _ST_WindVector.xyz, IN.texcoord1.w); 70 | #endif 71 | 72 | IN.vertex.xyz += billboardPos; 73 | IN.vertex.w = 1.0f; 74 | IN.normal = billboardNormal.xyz; 75 | IN.tangent = float4(billboardTangent.xyz,-1); 76 | 77 | float slices = unity_BillboardInfo.x; 78 | float invDelta = unity_BillboardInfo.y; 79 | angle += rotation; 80 | 81 | float imageIndex = fmod(floor(angle * invDelta + 0.5f), slices); 82 | float4 imageTexCoords = unity_BillboardImageTexCoords[imageIndex]; 83 | if (imageTexCoords.w < 0) 84 | { 85 | OUT.mainTexUV = imageTexCoords.xy - imageTexCoords.zw * percent.yx; 86 | } 87 | else 88 | { 89 | OUT.mainTexUV = imageTexCoords.xy + imageTexCoords.zw * percent; 90 | } 91 | 92 | OUT.color = _Color; 93 | 94 | #ifdef EFFECT_HUE_VARIATION 95 | float hueVariationAmount = frac(worldPos.x + worldPos.y + worldPos.z); 96 | OUT.HueVariationAmount = saturate(hueVariationAmount * _HueVariation.a); 97 | #endif 98 | } 99 | 100 | #endif // SPEEDTREE_BILLBOARD_COMMON_INCLUDED 101 |102 | 103 | 104 | -------------------------------------------------------------------------------- /Library/BuiltinShaders/CGIncludes/TerrainPreview.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) 6 | 7 | #ifndef TERRAIN_PREVIEW_INCLUDED 8 | #define TERRAIN_PREVIEW_INCLUDED 9 | 10 | 11 | // function to convert paint context pixels to heightmap uv 12 | sampler2D _Heightmap; 13 | float2 _HeightmapUV_PCPixelsX; 14 | float2 _HeightmapUV_PCPixelsY; 15 | float2 _HeightmapUV_Offset; 16 | float2 PaintContextPixelsToHeightmapUV(float2 pcPixels) 17 | { 18 | return _HeightmapUV_PCPixelsX * pcPixels.x + 19 | _HeightmapUV_PCPixelsY * pcPixels.y + 20 | _HeightmapUV_Offset; 21 | } 22 | 23 | // function to convert paint context pixels to object position (terrain position) 24 | float3 _ObjectPos_PCPixelsX; 25 | float3 _ObjectPos_PCPixelsY; 26 | float3 _ObjectPos_HeightMapSample; 27 | float3 _ObjectPos_Offset; 28 | float3 PaintContextPixelsToObjectPosition(float2 pcPixels, float heightmapSample) 29 | { 30 | // note: we could assume no object space rotation and make this dramatically simpler 31 | return _ObjectPos_PCPixelsX * pcPixels.x + 32 | _ObjectPos_PCPixelsY * pcPixels.y + 33 | _ObjectPos_HeightMapSample * heightmapSample + 34 | _ObjectPos_Offset; 35 | } 36 | 37 | // function to convert paint context pixels to brush uv 38 | float2 _BrushUV_PCPixelsX; 39 | float2 _BrushUV_PCPixelsY; 40 | float2 _BrushUV_Offset; 41 | float2 PaintContextPixelsToBrushUV(float2 pcPixels) 42 | { 43 | return _BrushUV_PCPixelsX * pcPixels.x + 44 | _BrushUV_PCPixelsY * pcPixels.y + 45 | _BrushUV_Offset; 46 | } 47 | 48 | // function to convert terrain object position to world position 49 | // We would normally use the ObjectToWorld / ObjectToClip calls to do this, but DrawProcedural does not set them 50 | // 'luckily' terrains cannot be rotated or scaled, so this transform is very simple 51 | float3 _TerrainObjectToWorldOffset; 52 | float3 TerrainObjectToWorldPosition(float3 objectPosition) 53 | { 54 | return objectPosition + _TerrainObjectToWorldOffset; 55 | } 56 | 57 | // function to build a procedural quad mesh 58 | // based on the quad resolution defined by _QuadRez 59 | // returns integer positions, starting with (0, 0), and ending with (_QuadRez.xy - 1) 60 | float3 _QuadRez; // quads X, quads Y, vertexCount 61 | float2 BuildProceduralQuadMeshVertex(uint vertexID) 62 | { 63 | int quadIndex = vertexID / 6; // quad index, each quad is made of 6 vertices 64 | int vertIndex = vertexID - quadIndex * 6; // vertex index within the quad [0..5] 65 | int qY = floor((quadIndex + 0.5f) / _QuadRez.x); // quad coords for current quad (Y) 66 | int qX = round(quadIndex - qY * _QuadRez.x); // quad coords for current quad (X) 67 | 68 | // each quad is defined by 6 vertices (two triangles), offset from (qX,qY) as follows: 69 | // vX = 0, 0, 1, 1, 1, 0 70 | // vY = 0, 1, 1, 1, 0, 0 71 | float sequence[6] = { 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f }; 72 | float vX = sequence[vertIndex]; 73 | float vY = sequence[5 - vertIndex]; // vY is just vX reversed 74 | float2 coord = float2(qX + vX, qY + vY); 75 | return coord; 76 | } 77 | 78 | 79 | float Stripe(in float x, in float stripeX, in float pixelWidth) 80 | { 81 | // compute derivatives to get ddx / pixel 82 | float2 derivatives = float2(ddx(x), ddy(x)); 83 | float derivLen = length(derivatives); 84 | float sharpen = 1.0f / max(derivLen, 0.00001f); 85 | return saturate(0.5f + 0.5f * (0.5f * pixelWidth - sharpen * abs(x - stripeX))); 86 | } 87 | 88 | #endif 89 |90 | 91 | 92 | -------------------------------------------------------------------------------- /Library/BuiltinShaders/CGIncludes/TerrainTool.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) 6 | 7 | #ifndef TERRAIN_TOOL_INCLUDED 8 | #define TERRAIN_TOOL_INCLUDED 9 | 10 | 11 | // function to convert paint context UV to brush uv 12 | float4 _PCUVToBrushUVScales; 13 | float2 _PCUVToBrushUVOffset; 14 | float2 PaintContextUVToBrushUV(float2 pcUV) 15 | { 16 | return _PCUVToBrushUVScales.xy * pcUV.x + 17 | _PCUVToBrushUVScales.zw * pcUV.y + 18 | _PCUVToBrushUVOffset; 19 | } 20 | 21 | 22 | float2 PaintContextUVToHeightmapUV(float2 pcUV) 23 | { 24 | return pcUV; 25 | } 26 | 27 | 28 | #endif 29 |30 | 31 | 32 | -------------------------------------------------------------------------------- /Library/BuiltinShaders/CGIncludes/Tessellation.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) 6 | 7 | #ifndef TESSELLATION_CGINC_INCLUDED 8 | #define TESSELLATION_CGINC_INCLUDED 9 | 10 | #include "UnityShaderVariables.cginc" 11 | 12 | // ---- utility functions 13 | 14 | float UnityCalcDistanceTessFactor (float4 vertex, float minDist, float maxDist, float tess) 15 | { 16 | float3 wpos = mul(unity_ObjectToWorld,vertex).xyz; 17 | float dist = distance (wpos, _WorldSpaceCameraPos); 18 | float f = clamp(1.0 - (dist - minDist) / (maxDist - minDist), 0.01, 1.0) * tess; 19 | return f; 20 | } 21 | 22 | float4 UnityCalcTriEdgeTessFactors (float3 triVertexFactors) 23 | { 24 | float4 tess; 25 | tess.x = 0.5 * (triVertexFactors.y + triVertexFactors.z); 26 | tess.y = 0.5 * (triVertexFactors.x + triVertexFactors.z); 27 | tess.z = 0.5 * (triVertexFactors.x + triVertexFactors.y); 28 | tess.w = (triVertexFactors.x + triVertexFactors.y + triVertexFactors.z) / 3.0f; 29 | return tess; 30 | } 31 | 32 | float UnityCalcEdgeTessFactor (float3 wpos0, float3 wpos1, float edgeLen) 33 | { 34 | // distance to edge center 35 | float dist = distance (0.5 * (wpos0+wpos1), _WorldSpaceCameraPos); 36 | // length of the edge 37 | float len = distance(wpos0, wpos1); 38 | // edgeLen is approximate desired size in pixels 39 | float f = max(len * _ScreenParams.y / (edgeLen * dist), 1.0); 40 | return f; 41 | } 42 | 43 | float UnityDistanceFromPlane (float3 pos, float4 plane) 44 | { 45 | float d = dot (float4(pos,1.0f), plane); 46 | return d; 47 | } 48 | 49 | 50 | // Returns true if triangle with given 3 world positions is outside of camera's view frustum. 51 | // cullEps is distance outside of frustum that is still considered to be inside (i.e. max displacement) 52 | bool UnityWorldViewFrustumCull (float3 wpos0, float3 wpos1, float3 wpos2, float cullEps) 53 | { 54 | float4 planeTest; 55 | 56 | // left 57 | planeTest.x = (( UnityDistanceFromPlane(wpos0, unity_CameraWorldClipPlanes[0]) > -cullEps) ? 1.0f : 0.0f ) + 58 | (( UnityDistanceFromPlane(wpos1, unity_CameraWorldClipPlanes[0]) > -cullEps) ? 1.0f : 0.0f ) + 59 | (( UnityDistanceFromPlane(wpos2, unity_CameraWorldClipPlanes[0]) > -cullEps) ? 1.0f : 0.0f ); 60 | // right 61 | planeTest.y = (( UnityDistanceFromPlane(wpos0, unity_CameraWorldClipPlanes[1]) > -cullEps) ? 1.0f : 0.0f ) + 62 | (( UnityDistanceFromPlane(wpos1, unity_CameraWorldClipPlanes[1]) > -cullEps) ? 1.0f : 0.0f ) + 63 | (( UnityDistanceFromPlane(wpos2, unity_CameraWorldClipPlanes[1]) > -cullEps) ? 1.0f : 0.0f ); 64 | // top 65 | planeTest.z = (( UnityDistanceFromPlane(wpos0, unity_CameraWorldClipPlanes[2]) > -cullEps) ? 1.0f : 0.0f ) + 66 | (( UnityDistanceFromPlane(wpos1, unity_CameraWorldClipPlanes[2]) > -cullEps) ? 1.0f : 0.0f ) + 67 | (( UnityDistanceFromPlane(wpos2, unity_CameraWorldClipPlanes[2]) > -cullEps) ? 1.0f : 0.0f ); 68 | // bottom 69 | planeTest.w = (( UnityDistanceFromPlane(wpos0, unity_CameraWorldClipPlanes[3]) > -cullEps) ? 1.0f : 0.0f ) + 70 | (( UnityDistanceFromPlane(wpos1, unity_CameraWorldClipPlanes[3]) > -cullEps) ? 1.0f : 0.0f ) + 71 | (( UnityDistanceFromPlane(wpos2, unity_CameraWorldClipPlanes[3]) > -cullEps) ? 1.0f : 0.0f ); 72 | 73 | // has to pass all 4 plane tests to be visible 74 | return !all (planeTest); 75 | } 76 | 77 | 78 | 79 | // ---- functions that compute tessellation factors 80 | 81 | 82 | // Distance based tessellation: 83 | // Tessellation level is "tess" before "minDist" from camera, and linearly decreases to 1 84 | // up to "maxDist" from camera. 85 | float4 UnityDistanceBasedTess (float4 v0, float4 v1, float4 v2, float minDist, float maxDist, float tess) 86 | { 87 | float3 f; 88 | f.x = UnityCalcDistanceTessFactor (v0,minDist,maxDist,tess); 89 | f.y = UnityCalcDistanceTessFactor (v1,minDist,maxDist,tess); 90 | f.z = UnityCalcDistanceTessFactor (v2,minDist,maxDist,tess); 91 | 92 | return UnityCalcTriEdgeTessFactors (f); 93 | } 94 | 95 | // Desired edge length based tessellation: 96 | // Approximate resulting edge length in pixels is "edgeLength". 97 | // Does not take viewing FOV into account, just flat out divides factor by distance. 98 | float4 UnityEdgeLengthBasedTess (float4 v0, float4 v1, float4 v2, float edgeLength) 99 | { 100 | float3 pos0 = mul(unity_ObjectToWorld,v0).xyz; 101 | float3 pos1 = mul(unity_ObjectToWorld,v1).xyz; 102 | float3 pos2 = mul(unity_ObjectToWorld,v2).xyz; 103 | float4 tess; 104 | tess.x = UnityCalcEdgeTessFactor (pos1, pos2, edgeLength); 105 | tess.y = UnityCalcEdgeTessFactor (pos2, pos0, edgeLength); 106 | tess.z = UnityCalcEdgeTessFactor (pos0, pos1, edgeLength); 107 | tess.w = (tess.x + tess.y + tess.z) / 3.0f; 108 | return tess; 109 | } 110 | 111 | 112 | // Same as UnityEdgeLengthBasedTess, but also does patch frustum culling: 113 | // patches outside of camera's view are culled before GPU tessellation. Saves some wasted work. 114 | float4 UnityEdgeLengthBasedTessCull (float4 v0, float4 v1, float4 v2, float edgeLength, float maxDisplacement) 115 | { 116 | float3 pos0 = mul(unity_ObjectToWorld,v0).xyz; 117 | float3 pos1 = mul(unity_ObjectToWorld,v1).xyz; 118 | float3 pos2 = mul(unity_ObjectToWorld,v2).xyz; 119 | float4 tess; 120 | 121 | if (UnityWorldViewFrustumCull(pos0, pos1, pos2, maxDisplacement)) 122 | { 123 | tess = 0.0f; 124 | } 125 | else 126 | { 127 | tess.x = UnityCalcEdgeTessFactor (pos1, pos2, edgeLength); 128 | tess.y = UnityCalcEdgeTessFactor (pos2, pos0, edgeLength); 129 | tess.z = UnityCalcEdgeTessFactor (pos0, pos1, edgeLength); 130 | tess.w = (tess.x + tess.y + tess.z) / 3.0f; 131 | } 132 | return tess; 133 | } 134 | 135 | 136 | 137 | #endif // TESSELLATION_CGINC_INCLUDED 138 |139 | 140 | 141 | -------------------------------------------------------------------------------- /Library/BuiltinShaders/CGIncludes/UnityDeferredLibrary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) 6 | #ifndef UNITY_DEFERRED_LIBRARY_INCLUDED 7 | #define UNITY_DEFERRED_LIBRARY_INCLUDED 8 | 9 | // Deferred lighting / shading helpers 10 | 11 | 12 | // -------------------------------------------------------- 13 | // Vertex shader 14 | 15 | struct unity_v2f_deferred { 16 | float4 pos : SV_POSITION; 17 | float4 uv : TEXCOORD0; 18 | float3 ray : TEXCOORD1; 19 | }; 20 | 21 | float _LightAsQuad; 22 | 23 | unity_v2f_deferred vert_deferred (float4 vertex : POSITION, float3 normal : NORMAL) 24 | { 25 | unity_v2f_deferred o; 26 | o.pos = UnityObjectToClipPos(vertex); 27 | o.uv = ComputeScreenPos(o.pos); 28 | o.ray = UnityObjectToViewPos(vertex) * float3(-1,-1,1); 29 | 30 | // normal contains a ray pointing from the camera to one of near plane's 31 | // corners in camera space when we are drawing a full screen quad. 32 | // Otherwise, when rendering 3D shapes, use the ray calculated here. 33 | o.ray = lerp(o.ray, normal, _LightAsQuad); 34 | 35 | return o; 36 | } 37 | 38 | 39 | // -------------------------------------------------------- 40 | // Shared uniforms 41 | 42 | 43 | UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture); 44 | 45 | float4 _LightDir; 46 | float4 _LightPos; 47 | float4 _LightColor; 48 | float4 unity_LightmapFade; 49 | float4x4 unity_WorldToLight; 50 | sampler2D_float _LightTextureB0; 51 | 52 | #if defined (POINT_COOKIE) 53 | samplerCUBE_float _LightTexture0; 54 | #else 55 | sampler2D_float _LightTexture0; 56 | #endif 57 | 58 | #if defined (SHADOWS_SCREEN) 59 | sampler2D _ShadowMapTexture; 60 | #endif 61 | 62 | #if defined (SHADOWS_SHADOWMASK) 63 | sampler2D _CameraGBufferTexture4; 64 | #endif 65 | 66 | // -------------------------------------------------------- 67 | // Shadow/fade helpers 68 | 69 | // Receiver plane depth bias create artifacts when depth is retrieved from 70 | // the depth buffer. see UnityGetReceiverPlaneDepthBias in UnityShadowLibrary.cginc 71 | #ifdef UNITY_USE_RECEIVER_PLANE_BIAS 72 | #undef UNITY_USE_RECEIVER_PLANE_BIAS 73 | #endif 74 | 75 | #include "UnityShadowLibrary.cginc" 76 | 77 | 78 | //Note : 79 | // SHADOWS_SHADOWMASK + LIGHTMAP_SHADOW_MIXING -> ShadowMask mode 80 | // SHADOWS_SHADOWMASK only -> Distance shadowmask mode 81 | 82 | // -------------------------------------------------------- 83 | half UnityDeferredSampleShadowMask(float2 uv) 84 | { 85 | half shadowMaskAttenuation = 1.0f; 86 | 87 | #if defined (SHADOWS_SHADOWMASK) 88 | half4 shadowMask = tex2D(_CameraGBufferTexture4, uv); 89 | shadowMaskAttenuation = saturate(dot(shadowMask, unity_OcclusionMaskSelector)); 90 | #endif 91 | 92 | return shadowMaskAttenuation; 93 | } 94 | 95 | // -------------------------------------------------------- 96 | half UnityDeferredSampleRealtimeShadow(half fade, float3 vec, float2 uv) 97 | { 98 | half shadowAttenuation = 1.0f; 99 | 100 | #if defined (DIRECTIONAL) || defined (DIRECTIONAL_COOKIE) 101 | #if defined(SHADOWS_SCREEN) 102 | shadowAttenuation = tex2D(_ShadowMapTexture, uv).r; 103 | #endif 104 | #endif 105 | 106 | #if defined(UNITY_FAST_COHERENT_DYNAMIC_BRANCHING) && defined(SHADOWS_SOFT) && !defined(LIGHTMAP_SHADOW_MIXING) 107 | //avoid expensive shadows fetches in the distance where coherency will be good 108 | UNITY_BRANCH 109 | if (fade < (1.0f - 1e-2f)) 110 | { 111 | #endif 112 | 113 | #if defined(SPOT) 114 | #if defined(SHADOWS_DEPTH) 115 | float4 shadowCoord = mul(unity_WorldToShadow[0], float4(vec, 1)); 116 | shadowAttenuation = UnitySampleShadowmap(shadowCoord); 117 | #endif 118 | #endif 119 | 120 | #if defined (POINT) || defined (POINT_COOKIE) 121 | #if defined(SHADOWS_CUBE) 122 | shadowAttenuation = UnitySampleShadowmap(vec); 123 | #endif 124 | #endif 125 | 126 | #if defined(UNITY_FAST_COHERENT_DYNAMIC_BRANCHING) && defined(SHADOWS_SOFT) && !defined(LIGHTMAP_SHADOW_MIXING) 127 | } 128 | #endif 129 | 130 | return shadowAttenuation; 131 | } 132 | 133 | // -------------------------------------------------------- 134 | half UnityDeferredComputeShadow(float3 vec, float fadeDist, float2 uv) 135 | { 136 | 137 | half fade = UnityComputeShadowFade(fadeDist); 138 | half shadowMaskAttenuation = UnityDeferredSampleShadowMask(uv); 139 | half realtimeShadowAttenuation = UnityDeferredSampleRealtimeShadow(fade, vec, uv); 140 | 141 | return UnityMixRealtimeAndBakedShadows(realtimeShadowAttenuation, shadowMaskAttenuation, fade); 142 | } 143 | 144 | // -------------------------------------------------------- 145 | // Common lighting data calculation (direction, attenuation, ...) 146 | void UnityDeferredCalculateLightParams ( 147 | unity_v2f_deferred i, 148 | out float3 outWorldPos, 149 | out float2 outUV, 150 | out half3 outLightDir, 151 | out float outAtten, 152 | out float outFadeDist) 153 | { 154 | i.ray = i.ray * (_ProjectionParams.z / i.ray.z); 155 | float2 uv = i.uv.xy / i.uv.w; 156 | 157 | // read depth and reconstruct world position 158 | float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv); 159 | depth = Linear01Depth (depth); 160 | float4 vpos = float4(i.ray * depth,1); 161 | float3 wpos = mul (unity_CameraToWorld, vpos).xyz; 162 | 163 | float fadeDist = UnityComputeShadowFadeDistance(wpos, vpos.z); 164 | 165 | // spot light case 166 | #if defined (SPOT) 167 | float3 tolight = _LightPos.xyz - wpos; 168 | half3 lightDir = normalize (tolight); 169 | 170 | float4 uvCookie = mul (unity_WorldToLight, float4(wpos,1)); 171 | // negative bias because http://aras-p.info/blog/2010/01/07/screenspace-vs-mip-mapping/ 172 | float atten = tex2Dbias (_LightTexture0, float4(uvCookie.xy / uvCookie.w, 0, -8)).w; 173 | atten *= uvCookie.w < 0; 174 | float att = dot(tolight, tolight) * _LightPos.w; 175 | atten *= tex2D (_LightTextureB0, att.rr).r; 176 | 177 | atten *= UnityDeferredComputeShadow (wpos, fadeDist, uv); 178 | 179 | // directional light case 180 | #elif defined (DIRECTIONAL) || defined (DIRECTIONAL_COOKIE) 181 | half3 lightDir = -_LightDir.xyz; 182 | float atten = 1.0; 183 | 184 | atten *= UnityDeferredComputeShadow (wpos, fadeDist, uv); 185 | 186 | #if defined (DIRECTIONAL_COOKIE) 187 | atten *= tex2Dbias (_LightTexture0, float4(mul(unity_WorldToLight, half4(wpos,1)).xy, 0, -8)).w; 188 | #endif //DIRECTIONAL_COOKIE 189 | 190 | // point light case 191 | #elif defined (POINT) || defined (POINT_COOKIE) 192 | float3 tolight = wpos - _LightPos.xyz; 193 | half3 lightDir = -normalize (tolight); 194 | 195 | float att = dot(tolight, tolight) * _LightPos.w; 196 | float atten = tex2D (_LightTextureB0, att.rr).r; 197 | 198 | atten *= UnityDeferredComputeShadow (tolight, fadeDist, uv); 199 | 200 | #if defined (POINT_COOKIE) 201 | atten *= texCUBEbias(_LightTexture0, float4(mul(unity_WorldToLight, half4(wpos,1)).xyz, -8)).w; 202 | #endif //POINT_COOKIE 203 | #else 204 | half3 lightDir = 0; 205 | float atten = 0; 206 | #endif 207 | 208 | outWorldPos = wpos; 209 | outUV = uv; 210 | outLightDir = lightDir; 211 | outAtten = atten; 212 | outFadeDist = fadeDist; 213 | } 214 | 215 | #endif // UNITY_DEFERRED_LIBRARY_INCLUDED 216 | 217 |218 | 219 | 220 | -------------------------------------------------------------------------------- /Library/BuiltinShaders/CGIncludes/UnityDeprecated.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) 6 | 7 | //----------------------------------------------------------------------------- 8 | // NOTICE: 9 | // All functions in this file are deprecated and should not be use, they will be remove in a later version. 10 | // They are let here for backward compatibility. 11 | // This file gather several function related to different part of shader code like BRDF or image based lighting 12 | // to avoid to create multiple deprecated file, this file include deprecated function based on a define 13 | // to when including this file, it is expected that the caller define which deprecated function group he want to enable 14 | // Example, following code will include all deprecated BRDF functions: 15 | // #define INCLUDE_UNITY_STANDARD_BRDF_DEPRECATED 16 | // #include "UnityDeprecated.cginc" 17 | // #undef INCLUDE_UNITY_STANDARD_BRDF_DEPRECATED 18 | //----------------------------------------------------------------------------- 19 | 20 | #ifdef INCLUDE_UNITY_STANDARD_BRDF_DEPRECATED 21 | 22 | inline half3 LazarovFresnelTerm (half3 F0, half roughness, half cosA) 23 | { 24 | half t = Pow5 (1 - cosA); // ala Schlick interpoliation 25 | t /= 4 - 3 * roughness; 26 | return F0 + (1-F0) * t; 27 | } 28 | inline half3 SebLagardeFresnelTerm (half3 F0, half roughness, half cosA) 29 | { 30 | half t = Pow5 (1 - cosA); // ala Schlick interpoliation 31 | return F0 + (max (F0, roughness) - F0) * t; 32 | } 33 | 34 | // Cook-Torrance visibility term, doesn't take roughness into account 35 | inline half CookTorranceVisibilityTerm (half NdotL, half NdotV, half NdotH, half VdotH) 36 | { 37 | VdotH += 1e-5f; 38 | half G = min (1.0, min ( 39 | (2.0 * NdotH * NdotV) / VdotH, 40 | (2.0 * NdotH * NdotL) / VdotH)); 41 | return G / (NdotL * NdotV + 1e-4f); 42 | } 43 | 44 | // Kelemen-Szirmay-Kalos is an approximation to Cook-Torrance visibility term 45 | // http://sirkan.iit.bme.hu/~szirmay/scook.pdf 46 | inline half KelemenVisibilityTerm (half LdotH) 47 | { 48 | return 1.0 / (LdotH * LdotH); 49 | } 50 | 51 | // Modified Kelemen-Szirmay-Kalos which takes roughness into account, based on: http://www.filmicworlds.com/2014/04/21/optimizing-ggx-shaders-with-dotlh/ 52 | inline half ModifiedKelemenVisibilityTerm (half LdotH, half perceptualRoughness) 53 | { 54 | half c = 0.797884560802865h; // c = sqrt(2 / Pi) 55 | half k = PerceptualRoughnessToRoughness(perceptualRoughness) * c; 56 | half gH = LdotH * (1-k) + k; 57 | return 1.0 / (gH * gH); 58 | } 59 | 60 | // Smith-Schlick derived for GGX 61 | inline half SmithGGXVisibilityTerm (half NdotL, half NdotV, half perceptualRoughness) 62 | { 63 | half k = (PerceptualRoughnessToRoughness(perceptualRoughness)) / 2; // derived by B. Karis, http://graphicrants.blogspot.se/2013/08/specular-brdf-reference.html 64 | return SmithVisibilityTerm (NdotL, NdotV, k); 65 | } 66 | 67 | inline half ImplicitVisibilityTerm () 68 | { 69 | return 1; 70 | } 71 | 72 | // BlinnPhong normalized as reflection densitysity function (RDF) 73 | // ready for use directly as specular: spec=D 74 | // http://www.thetenthplanet.de/archives/255 75 | inline half RDFBlinnPhongNormalizedTerm (half NdotH, half n) 76 | { 77 | half normTerm = (n + 2.0) / (8.0 * UNITY_PI); 78 | half specTerm = pow (NdotH, n); 79 | return specTerm * normTerm; 80 | } 81 | 82 | // Decodes HDR textures 83 | // sm 2.0 is no longer supported 84 | inline half3 DecodeHDR_NoLinearSupportInSM2 (half4 data, half4 decodeInstructions) 85 | { 86 | // If Linear mode is not supported we can skip exponent part 87 | // In Standard shader SM2.0 and SM3.0 paths are always using different shader variations 88 | // SM2.0: hardware does not support Linear, we can skip exponent part 89 | #if defined(UNITY_COLORSPACE_GAMMA) && (SHADER_TARGET < 30) 90 | return (data.a * decodeInstructions.x) * data.rgb; 91 | #else 92 | return DecodeHDR(data, decodeInstructions); 93 | #endif 94 | } 95 | 96 | inline half DotClamped (half3 a, half3 b) 97 | { 98 | #if (SHADER_TARGET < 30) 99 | return saturate(dot(a, b)); 100 | #else 101 | return max(0.0h, dot(a, b)); 102 | #endif 103 | } 104 | 105 | inline half LambertTerm (half3 normal, half3 lightDir) 106 | { 107 | return DotClamped (normal, lightDir); 108 | } 109 | 110 | inline half BlinnTerm (half3 normal, half3 halfDir) 111 | { 112 | return DotClamped (normal, halfDir); 113 | } 114 | 115 | half RoughnessToSpecPower (half roughness) 116 | { 117 | return PerceptualRoughnessToSpecPower (roughness); 118 | } 119 | 120 | //------------------------------------------------------------------------------------- 121 | // Legacy, to keep backwards compatibility for (pre Unity 5.3) custom user shaders: 122 | #ifdef UNITY_COLORSPACE_GAMMA 123 | # define unity_LightGammaCorrectionConsts_PIDiv4 ((UNITY_PI/4)*(UNITY_PI/4)) 124 | # define unity_LightGammaCorrectionConsts_HalfDivPI ((.5h/UNITY_PI)*(.5h/UNITY_PI)) 125 | # define unity_LightGammaCorrectionConsts_8 (8*8) 126 | # define unity_LightGammaCorrectionConsts_SqrtHalfPI (2/UNITY_PI) 127 | #else 128 | # define unity_LightGammaCorrectionConsts_PIDiv4 (UNITY_PI/4) 129 | # define unity_LightGammaCorrectionConsts_HalfDivPI (.5h/UNITY_PI) 130 | # define unity_LightGammaCorrectionConsts_8 (8) 131 | # define unity_LightGammaCorrectionConsts_SqrtHalfPI (0.79788) 132 | #endif 133 | 134 | #endif // INCLUDE_UNITY_STANDARD_BRDF_DEPRECATED 135 | 136 | #ifdef INCLUDE_UNITY_IMAGE_BASED_LIGHTING_DEPRECATED 137 | 138 | // Old Unity_GlossyEnvironment signature. Kept only for backward compatibility and will be removed soon 139 | half3 Unity_GlossyEnvironment (UNITY_ARGS_TEXCUBE(tex), half4 hdr, half3 worldNormal, half perceptualRoughness) 140 | { 141 | Unity_GlossyEnvironmentData g; 142 | g.roughness /* perceptualRoughness */ = perceptualRoughness; 143 | g.reflUVW = worldNormal; 144 | 145 | return Unity_GlossyEnvironment (UNITY_PASS_TEXCUBE(tex), hdr, g); 146 | } 147 | 148 | #endif // INCLUDE_UNITY_IMAGE_BASED_LIGHTING_DEPRECATED 149 |150 | 151 | 152 | -------------------------------------------------------------------------------- /Library/BuiltinShaders/CGIncludes/UnityGBuffer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) 6 | 7 | #ifndef UNITY_GBUFFER_INCLUDED 8 | #define UNITY_GBUFFER_INCLUDED 9 | 10 | //----------------------------------------------------------------------------- 11 | // Main structure that store the data from the standard shader (i.e user input) 12 | struct UnityStandardData 13 | { 14 | half3 diffuseColor; 15 | half occlusion; 16 | 17 | half3 specularColor; 18 | half smoothness; 19 | 20 | float3 normalWorld; // normal in world space 21 | }; 22 | 23 | //----------------------------------------------------------------------------- 24 | // This will encode UnityStandardData into GBuffer 25 | void UnityStandardDataToGbuffer(UnityStandardData data, out half4 outGBuffer0, out half4 outGBuffer1, out half4 outGBuffer2) 26 | { 27 | // RT0: diffuse color (rgb), occlusion (a) - sRGB rendertarget 28 | outGBuffer0 = half4(data.diffuseColor, data.occlusion); 29 | 30 | // RT1: spec color (rgb), smoothness (a) - sRGB rendertarget 31 | outGBuffer1 = half4(data.specularColor, data.smoothness); 32 | 33 | // RT2: normal (rgb), --unused, very low precision-- (a) 34 | outGBuffer2 = half4(data.normalWorld * 0.5f + 0.5f, 1.0f); 35 | } 36 | //----------------------------------------------------------------------------- 37 | // This decode the Gbuffer in a UnityStandardData struct 38 | UnityStandardData UnityStandardDataFromGbuffer(half4 inGBuffer0, half4 inGBuffer1, half4 inGBuffer2) 39 | { 40 | UnityStandardData data; 41 | 42 | data.diffuseColor = inGBuffer0.rgb; 43 | data.occlusion = inGBuffer0.a; 44 | 45 | data.specularColor = inGBuffer1.rgb; 46 | data.smoothness = inGBuffer1.a; 47 | 48 | data.normalWorld = normalize((float3)inGBuffer2.rgb * 2 - 1); 49 | 50 | return data; 51 | } 52 | //----------------------------------------------------------------------------- 53 | // In some cases like for terrain, the user want to apply a specific weight to the attribute 54 | // The function below is use for this 55 | void UnityStandardDataApplyWeightToGbuffer(inout half4 inOutGBuffer0, inout half4 inOutGBuffer1, inout half4 inOutGBuffer2, half alpha) 56 | { 57 | // With UnityStandardData current encoding, We can apply the weigth directly on the gbuffer 58 | inOutGBuffer0.rgb *= alpha; // diffuseColor 59 | inOutGBuffer1 *= alpha; // SpecularColor and Smoothness 60 | inOutGBuffer2.rgb *= alpha; // Normal 61 | } 62 | //----------------------------------------------------------------------------- 63 | 64 | #endif // #ifndef UNITY_GBUFFER_INCLUDED 65 |66 | 67 | 68 | -------------------------------------------------------------------------------- /Library/BuiltinShaders/CGIncludes/UnityLightingCommon.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) 5 | 6 | #ifndef UNITY_LIGHTING_COMMON_INCLUDED 7 | #define UNITY_LIGHTING_COMMON_INCLUDED 8 | 9 | fixed4 _LightColor0; 10 | fixed4 _SpecColor; 11 | 12 | struct UnityLight 13 | { 14 | half3 color; 15 | half3 dir; 16 | half ndotl; // Deprecated: Ndotl is now calculated on the fly and is no longer stored. Do not used it. 17 | }; 18 | 19 | struct UnityIndirect 20 | { 21 | half3 diffuse; 22 | half3 specular; 23 | }; 24 | 25 | struct UnityGI 26 | { 27 | UnityLight light; 28 | UnityIndirect indirect; 29 | }; 30 | 31 | struct UnityGIInput 32 | { 33 | UnityLight light; // pixel light, sent from the engine 34 | 35 | float3 worldPos; 36 | half3 worldViewDir; 37 | half atten; 38 | half3 ambient; 39 | 40 | // interpolated lightmap UVs are passed as full float precision data to fragment shaders 41 | // so lightmapUV (which is used as a tmp inside of lightmap fragment shaders) should 42 | // also be full float precision to avoid data loss before sampling a texture. 43 | float4 lightmapUV; // .xy = static lightmap UV, .zw = dynamic lightmap UV 44 | 45 | #if defined(UNITY_SPECCUBE_BLENDING) || defined(UNITY_SPECCUBE_BOX_PROJECTION) || defined(UNITY_ENABLE_REFLECTION_BUFFERS) 46 | float4 boxMin[2]; 47 | #endif 48 | #ifdef UNITY_SPECCUBE_BOX_PROJECTION 49 | float4 boxMax[2]; 50 | float4 probePosition[2]; 51 | #endif 52 | // HDR cubemap properties, use to decompress HDR texture 53 | float4 probeHDR[2]; 54 | }; 55 | 56 | #endif 57 | 58 |59 | 60 | 61 | -------------------------------------------------------------------------------- /Library/BuiltinShaders/CGIncludes/UnityShaderUtilities.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) 6 | 7 | #ifndef UNITY_SHADER_UTILITIES_INCLUDED 8 | #define UNITY_SHADER_UTILITIES_INCLUDED 9 | 10 | // This file is always included in all unity shaders. 11 | 12 | #include "UnityShaderVariables.cginc" 13 | 14 | float3 ODSOffset(float3 worldPos, float ipd) 15 | { 16 | //based on google's omni-directional stereo rendering thread 17 | const float EPSILON = 2.4414e-4; 18 | float3 worldUp = float3(0.0, 1.0, 0.0); 19 | float3 camOffset = worldPos.xyz - _WorldSpaceCameraPos.xyz; 20 | float4 direction = float4(camOffset.xyz, dot(camOffset.xyz, camOffset.xyz)); 21 | direction.w = max(EPSILON, direction.w); 22 | direction *= rsqrt(direction.w); 23 | 24 | float3 tangent = cross(direction.xyz, worldUp.xyz); 25 | if (dot(tangent, tangent) < EPSILON) 26 | return float3(0, 0, 0); 27 | tangent = normalize(tangent); 28 | 29 | float directionMinusIPD = max(EPSILON, direction.w*direction.w - ipd*ipd); 30 | float a = ipd * ipd / direction.w; 31 | float b = ipd / direction.w * sqrt(directionMinusIPD); 32 | float3 offset = -a*direction + b*tangent; 33 | return offset; 34 | } 35 | 36 | inline float4 UnityObjectToClipPosODS(float3 inPos) 37 | { 38 | float4 clipPos; 39 | float3 posWorld = mul(unity_ObjectToWorld, float4(inPos, 1.0)).xyz; 40 | #if defined(STEREO_CUBEMAP_RENDER_ON) 41 | float3 offset = ODSOffset(posWorld, unity_HalfStereoSeparation.x); 42 | clipPos = mul(UNITY_MATRIX_VP, float4(posWorld + offset, 1.0)); 43 | #else 44 | clipPos = mul(UNITY_MATRIX_VP, float4(posWorld, 1.0)); 45 | #endif 46 | return clipPos; 47 | } 48 | 49 | // Tranforms position from object to homogenous space 50 | inline float4 UnityObjectToClipPos(in float3 pos) 51 | { 52 | #if defined(STEREO_CUBEMAP_RENDER_ON) 53 | return UnityObjectToClipPosODS(pos); 54 | #else 55 | // More efficient than computing M*VP matrix product 56 | return mul(UNITY_MATRIX_VP, mul(unity_ObjectToWorld, float4(pos, 1.0))); 57 | #endif 58 | } 59 | inline float4 UnityObjectToClipPos(float4 pos) // overload for float4; avoids "implicit truncation" warning for existing shaders 60 | { 61 | return UnityObjectToClipPos(pos.xyz); 62 | } 63 | 64 | #endif 65 |66 | 67 | 68 | -------------------------------------------------------------------------------- /Library/BuiltinShaders/CGIncludes/UnitySprites.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) 6 | 7 | #ifndef UNITY_SPRITES_INCLUDED 8 | #define UNITY_SPRITES_INCLUDED 9 | 10 | #include "UnityCG.cginc" 11 | 12 | #ifdef UNITY_INSTANCING_ENABLED 13 | 14 | UNITY_INSTANCING_BUFFER_START(PerDrawSprite) 15 | // SpriteRenderer.Color while Non-Batched/Instanced. 16 | UNITY_DEFINE_INSTANCED_PROP(fixed4, unity_SpriteRendererColorArray) 17 | // this could be smaller but that's how bit each entry is regardless of type 18 | UNITY_DEFINE_INSTANCED_PROP(fixed2, unity_SpriteFlipArray) 19 | UNITY_INSTANCING_BUFFER_END(PerDrawSprite) 20 | 21 | #define _RendererColor UNITY_ACCESS_INSTANCED_PROP(PerDrawSprite, unity_SpriteRendererColorArray) 22 | #define _Flip UNITY_ACCESS_INSTANCED_PROP(PerDrawSprite, unity_SpriteFlipArray) 23 | 24 | #endif // instancing 25 | 26 | CBUFFER_START(UnityPerDrawSprite) 27 | #ifndef UNITY_INSTANCING_ENABLED 28 | fixed4 _RendererColor; 29 | fixed2 _Flip; 30 | #endif 31 | float _EnableExternalAlpha; 32 | CBUFFER_END 33 | 34 | // Material Color. 35 | fixed4 _Color; 36 | 37 | struct appdata_t 38 | { 39 | float4 vertex : POSITION; 40 | float4 color : COLOR; 41 | float2 texcoord : TEXCOORD0; 42 | UNITY_VERTEX_INPUT_INSTANCE_ID 43 | }; 44 | 45 | struct v2f 46 | { 47 | float4 vertex : SV_POSITION; 48 | fixed4 color : COLOR; 49 | float2 texcoord : TEXCOORD0; 50 | UNITY_VERTEX_OUTPUT_STEREO 51 | }; 52 | 53 | inline float4 UnityFlipSprite(in float3 pos, in fixed2 flip) 54 | { 55 | return float4(pos.xy * flip, pos.z, 1.0); 56 | } 57 | 58 | v2f SpriteVert(appdata_t IN) 59 | { 60 | v2f OUT; 61 | 62 | UNITY_SETUP_INSTANCE_ID (IN); 63 | UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT); 64 | 65 | OUT.vertex = UnityFlipSprite(IN.vertex, _Flip); 66 | OUT.vertex = UnityObjectToClipPos(OUT.vertex); 67 | OUT.texcoord = IN.texcoord; 68 | OUT.color = IN.color * _Color * _RendererColor; 69 | 70 | #ifdef PIXELSNAP_ON 71 | OUT.vertex = UnityPixelSnap (OUT.vertex); 72 | #endif 73 | 74 | return OUT; 75 | } 76 | 77 | sampler2D _MainTex; 78 | sampler2D _AlphaTex; 79 | 80 | fixed4 SampleSpriteTexture(float2 uv) 81 | { 82 | fixed4 color = tex2D (_MainTex, uv); 83 | 84 | #if ETC1_EXTERNAL_ALPHA 85 | fixed4 alpha = tex2D (_AlphaTex, uv); 86 | color.a = lerp (color.a, alpha.r, _EnableExternalAlpha); 87 | #endif 88 | 89 | return color; 90 | } 91 | 92 | fixed4 SpriteFrag(v2f IN) : SV_Target 93 | { 94 | fixed4 c = SampleSpriteTexture (IN.texcoord) * IN.color; 95 | c.rgb *= c.a; 96 | return c; 97 | } 98 | 99 | #endif // UNITY_SPRITES_INCLUDED 100 |101 | 102 | 103 | -------------------------------------------------------------------------------- /Library/BuiltinShaders/CGIncludes/UnityStandardConfig.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt 4 | #ifndef UNITY_STANDARD_CONFIG_INCLUDED 5 | #define UNITY_STANDARD_CONFIG_INCLUDED 6 | 7 | // Define Specular cubemap constants 8 | #ifndef UNITY_SPECCUBE_LOD_EXPONENT 9 | #define UNITY_SPECCUBE_LOD_EXPONENT (1.5) 10 | #endif 11 | #ifndef UNITY_SPECCUBE_LOD_STEPS 12 | #define UNITY_SPECCUBE_LOD_STEPS (6) 13 | #endif 14 | 15 | // Energy conservation for Specular workflow is Monochrome. For instance: Red metal will make diffuse Black not Cyan 16 | #ifndef UNITY_CONSERVE_ENERGY 17 | #define UNITY_CONSERVE_ENERGY 1 18 | #endif 19 | #ifndef UNITY_CONSERVE_ENERGY_MONOCHROME 20 | #define UNITY_CONSERVE_ENERGY_MONOCHROME 1 21 | #endif 22 | 23 | // "platform caps" defines: they are controlled from TierSettings (Editor will determine values and pass them to compiler) 24 | // UNITY_SPECCUBE_BOX_PROJECTION: TierSettings.reflectionProbeBoxProjection 25 | // UNITY_SPECCUBE_BLENDING: TierSettings.reflectionProbeBlending 26 | // UNITY_ENABLE_DETAIL_NORMALMAP: TierSettings.detailNormalMap 27 | // UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS: TierSettings.semitransparentShadows 28 | 29 | // disregarding what is set in TierSettings, some features have hardware restrictions 30 | // so we still add safety net, otherwise we might end up with shaders failing to compile 31 | 32 | #if defined(SHADER_TARGET_SURFACE_ANALYSIS) 33 | // For surface shader code analysis pass, disable some features that don't affect inputs/outputs 34 | #undef UNITY_SPECCUBE_BOX_PROJECTION 35 | #undef UNITY_SPECCUBE_BLENDING 36 | #undef UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS 37 | #elif SHADER_TARGET < 30 38 | #undef UNITY_SPECCUBE_BOX_PROJECTION 39 | #undef UNITY_SPECCUBE_BLENDING 40 | #undef UNITY_ENABLE_DETAIL_NORMALMAP 41 | #ifdef _PARALLAXMAP 42 | #undef _PARALLAXMAP 43 | #endif 44 | #endif 45 | #if (SHADER_TARGET < 30) || defined(SHADER_API_GLES) 46 | #undef UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS 47 | #endif 48 | 49 | #ifndef UNITY_SAMPLE_FULL_SH_PER_PIXEL 50 | // Lightmap UVs and ambient color from SHL2 are shared in the vertex to pixel interpolators. Do full SH evaluation in the pixel shader when static lightmap and LIGHTPROBE_SH is enabled. 51 | #define UNITY_SAMPLE_FULL_SH_PER_PIXEL (LIGHTMAP_ON && LIGHTPROBE_SH) 52 | 53 | // Shaders might fail to compile due to shader instruction count limit. Leave only baked lightmaps on SM20 hardware. 54 | #if UNITY_SAMPLE_FULL_SH_PER_PIXEL && (SHADER_TARGET < 25) 55 | #undef UNITY_SAMPLE_FULL_SH_PER_PIXEL 56 | #undef LIGHTPROBE_SH 57 | #endif 58 | #endif 59 | 60 | #ifndef UNITY_BRDF_GGX 61 | #define UNITY_BRDF_GGX 1 62 | #endif 63 | 64 | // Orthnormalize Tangent Space basis per-pixel 65 | // Necessary to support high-quality normal-maps. Compatible with Maya and Marmoset. 66 | // However xNormal expects oldschool non-orthnormalized basis - essentially preventing good looking normal-maps :( 67 | // Due to the fact that xNormal is probably _the most used tool to bake out normal-maps today_ we have to stick to old ways for now. 68 | // 69 | // Disabled by default, until xNormal has an option to bake proper normal-maps. 70 | #ifndef UNITY_TANGENT_ORTHONORMALIZE 71 | #define UNITY_TANGENT_ORTHONORMALIZE 0 72 | #endif 73 | 74 | 75 | // Some extra optimizations 76 | 77 | // Simplified Standard Shader is off by default and should not be used for Legacy Shaders 78 | #ifndef UNITY_STANDARD_SIMPLE 79 | #define UNITY_STANDARD_SIMPLE 0 80 | #endif 81 | 82 | // Setup a new define with meaningful name to know if we require world pos in fragment shader 83 | #if UNITY_STANDARD_SIMPLE 84 | #define UNITY_REQUIRE_FRAG_WORLDPOS 0 85 | #else 86 | #define UNITY_REQUIRE_FRAG_WORLDPOS 1 87 | #endif 88 | 89 | // Should we pack worldPos along tangent (saving an interpolator) 90 | // We want to skip this on mobile platforms, because worldpos gets packed into mediump 91 | #if UNITY_REQUIRE_FRAG_WORLDPOS && !defined(_PARALLAXMAP) && !defined(SHADER_API_MOBILE) 92 | #define UNITY_PACK_WORLDPOS_WITH_TANGENT 1 93 | #else 94 | #define UNITY_PACK_WORLDPOS_WITH_TANGENT 0 95 | #endif 96 | 97 | #endif // UNITY_STANDARD_CONFIG_INCLUDED 98 |99 | 100 | 101 | -------------------------------------------------------------------------------- /Library/BuiltinShaders/CGIncludes/UnityStandardCoreForward.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) 6 | 7 | #ifndef UNITY_STANDARD_CORE_FORWARD_INCLUDED 8 | #define UNITY_STANDARD_CORE_FORWARD_INCLUDED 9 | 10 | #if defined(UNITY_NO_FULL_STANDARD_SHADER) 11 | # define UNITY_STANDARD_SIMPLE 1 12 | #endif 13 | 14 | #include "UnityStandardConfig.cginc" 15 | 16 | #if UNITY_STANDARD_SIMPLE 17 | #include "UnityStandardCoreForwardSimple.cginc" 18 | VertexOutputBaseSimple vertBase (VertexInput v) { return vertForwardBaseSimple(v); } 19 | VertexOutputForwardAddSimple vertAdd (VertexInput v) { return vertForwardAddSimple(v); } 20 | half4 fragBase (VertexOutputBaseSimple i) : SV_Target { return fragForwardBaseSimpleInternal(i); } 21 | half4 fragAdd (VertexOutputForwardAddSimple i) : SV_Target { return fragForwardAddSimpleInternal(i); } 22 | #else 23 | #include "UnityStandardCore.cginc" 24 | VertexOutputForwardBase vertBase (VertexInput v) { return vertForwardBase(v); } 25 | VertexOutputForwardAdd vertAdd (VertexInput v) { return vertForwardAdd(v); } 26 | half4 fragBase (VertexOutputForwardBase i) : SV_Target { return fragForwardBaseInternal(i); } 27 | half4 fragAdd (VertexOutputForwardAdd i) : SV_Target { return fragForwardAddInternal(i); } 28 | #endif 29 | 30 | #endif // UNITY_STANDARD_CORE_FORWARD_INCLUDED 31 |32 | 33 | 34 | -------------------------------------------------------------------------------- /Library/BuiltinShaders/CGIncludes/UnityStandardInput.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) 6 | 7 | #ifndef UNITY_STANDARD_INPUT_INCLUDED 8 | #define UNITY_STANDARD_INPUT_INCLUDED 9 | 10 | #include "UnityCG.cginc" 11 | #include "UnityStandardConfig.cginc" 12 | #include "UnityPBSLighting.cginc" // TBD: remove 13 | #include "UnityStandardUtils.cginc" 14 | 15 | //--------------------------------------- 16 | // Directional lightmaps & Parallax require tangent space too 17 | #if (_NORMALMAP || DIRLIGHTMAP_COMBINED || _PARALLAXMAP) 18 | #define _TANGENT_TO_WORLD 1 19 | #endif 20 | 21 | #if (_DETAIL_MULX2 || _DETAIL_MUL || _DETAIL_ADD || _DETAIL_LERP) 22 | #define _DETAIL 1 23 | #endif 24 | 25 | //--------------------------------------- 26 | half4 _Color; 27 | half _Cutoff; 28 | 29 | sampler2D _MainTex; 30 | float4 _MainTex_ST; 31 | 32 | sampler2D _DetailAlbedoMap; 33 | float4 _DetailAlbedoMap_ST; 34 | 35 | sampler2D _BumpMap; 36 | half _BumpScale; 37 | 38 | sampler2D _DetailMask; 39 | sampler2D _DetailNormalMap; 40 | half _DetailNormalMapScale; 41 | 42 | sampler2D _SpecGlossMap; 43 | sampler2D _MetallicGlossMap; 44 | half _Metallic; 45 | float _Glossiness; 46 | float _GlossMapScale; 47 | 48 | sampler2D _OcclusionMap; 49 | half _OcclusionStrength; 50 | 51 | sampler2D _ParallaxMap; 52 | half _Parallax; 53 | half _UVSec; 54 | 55 | half4 _EmissionColor; 56 | sampler2D _EmissionMap; 57 | 58 | //------------------------------------------------------------------------------------- 59 | // Input functions 60 | 61 | struct VertexInput 62 | { 63 | float4 vertex : POSITION; 64 | half3 normal : NORMAL; 65 | float2 uv0 : TEXCOORD0; 66 | float2 uv1 : TEXCOORD1; 67 | #if defined(DYNAMICLIGHTMAP_ON) || defined(UNITY_PASS_META) 68 | float2 uv2 : TEXCOORD2; 69 | #endif 70 | #ifdef _TANGENT_TO_WORLD 71 | half4 tangent : TANGENT; 72 | #endif 73 | UNITY_VERTEX_INPUT_INSTANCE_ID 74 | }; 75 | 76 | float4 TexCoords(VertexInput v) 77 | { 78 | float4 texcoord; 79 | texcoord.xy = TRANSFORM_TEX(v.uv0, _MainTex); // Always source from uv0 80 | texcoord.zw = TRANSFORM_TEX(((_UVSec == 0) ? v.uv0 : v.uv1), _DetailAlbedoMap); 81 | return texcoord; 82 | } 83 | 84 | half DetailMask(float2 uv) 85 | { 86 | return tex2D (_DetailMask, uv).a; 87 | } 88 | 89 | half3 Albedo(float4 texcoords) 90 | { 91 | half3 albedo = _Color.rgb * tex2D (_MainTex, texcoords.xy).rgb; 92 | #if _DETAIL 93 | #if (SHADER_TARGET < 30) 94 | // SM20: instruction count limitation 95 | // SM20: no detail mask 96 | half mask = 1; 97 | #else 98 | half mask = DetailMask(texcoords.xy); 99 | #endif 100 | half3 detailAlbedo = tex2D (_DetailAlbedoMap, texcoords.zw).rgb; 101 | #if _DETAIL_MULX2 102 | albedo *= LerpWhiteTo (detailAlbedo * unity_ColorSpaceDouble.rgb, mask); 103 | #elif _DETAIL_MUL 104 | albedo *= LerpWhiteTo (detailAlbedo, mask); 105 | #elif _DETAIL_ADD 106 | albedo += detailAlbedo * mask; 107 | #elif _DETAIL_LERP 108 | albedo = lerp (albedo, detailAlbedo, mask); 109 | #endif 110 | #endif 111 | return albedo; 112 | } 113 | 114 | half Alpha(float2 uv) 115 | { 116 | #if defined(_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A) 117 | return _Color.a; 118 | #else 119 | return tex2D(_MainTex, uv).a * _Color.a; 120 | #endif 121 | } 122 | 123 | half Occlusion(float2 uv) 124 | { 125 | #if (SHADER_TARGET < 30) 126 | // SM20: instruction count limitation 127 | // SM20: simpler occlusion 128 | return tex2D(_OcclusionMap, uv).g; 129 | #else 130 | half occ = tex2D(_OcclusionMap, uv).g; 131 | return LerpOneTo (occ, _OcclusionStrength); 132 | #endif 133 | } 134 | 135 | half4 SpecularGloss(float2 uv) 136 | { 137 | half4 sg; 138 | #ifdef _SPECGLOSSMAP 139 | #if defined(_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A) 140 | sg.rgb = tex2D(_SpecGlossMap, uv).rgb; 141 | sg.a = tex2D(_MainTex, uv).a; 142 | #else 143 | sg = tex2D(_SpecGlossMap, uv); 144 | #endif 145 | sg.a *= _GlossMapScale; 146 | #else 147 | sg.rgb = _SpecColor.rgb; 148 | #ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A 149 | sg.a = tex2D(_MainTex, uv).a * _GlossMapScale; 150 | #else 151 | sg.a = _Glossiness; 152 | #endif 153 | #endif 154 | return sg; 155 | } 156 | 157 | half2 MetallicGloss(float2 uv) 158 | { 159 | half2 mg; 160 | 161 | #ifdef _METALLICGLOSSMAP 162 | #ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A 163 | mg.r = tex2D(_MetallicGlossMap, uv).r; 164 | mg.g = tex2D(_MainTex, uv).a; 165 | #else 166 | mg = tex2D(_MetallicGlossMap, uv).ra; 167 | #endif 168 | mg.g *= _GlossMapScale; 169 | #else 170 | mg.r = _Metallic; 171 | #ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A 172 | mg.g = tex2D(_MainTex, uv).a * _GlossMapScale; 173 | #else 174 | mg.g = _Glossiness; 175 | #endif 176 | #endif 177 | return mg; 178 | } 179 | 180 | half2 MetallicRough(float2 uv) 181 | { 182 | half2 mg; 183 | #ifdef _METALLICGLOSSMAP 184 | mg.r = tex2D(_MetallicGlossMap, uv).r; 185 | #else 186 | mg.r = _Metallic; 187 | #endif 188 | 189 | #ifdef _SPECGLOSSMAP 190 | mg.g = 1.0f - tex2D(_SpecGlossMap, uv).r; 191 | #else 192 | mg.g = 1.0f - _Glossiness; 193 | #endif 194 | return mg; 195 | } 196 | 197 | half3 Emission(float2 uv) 198 | { 199 | #ifndef _EMISSION 200 | return 0; 201 | #else 202 | return tex2D(_EmissionMap, uv).rgb * _EmissionColor.rgb; 203 | #endif 204 | } 205 | 206 | #ifdef _NORMALMAP 207 | half3 NormalInTangentSpace(float4 texcoords) 208 | { 209 | half3 normalTangent = UnpackScaleNormal(tex2D (_BumpMap, texcoords.xy), _BumpScale); 210 | 211 | #if _DETAIL && defined(UNITY_ENABLE_DETAIL_NORMALMAP) 212 | half mask = DetailMask(texcoords.xy); 213 | half3 detailNormalTangent = UnpackScaleNormal(tex2D (_DetailNormalMap, texcoords.zw), _DetailNormalMapScale); 214 | #if _DETAIL_LERP 215 | normalTangent = lerp( 216 | normalTangent, 217 | detailNormalTangent, 218 | mask); 219 | #else 220 | normalTangent = lerp( 221 | normalTangent, 222 | BlendNormals(normalTangent, detailNormalTangent), 223 | mask); 224 | #endif 225 | #endif 226 | 227 | return normalTangent; 228 | } 229 | #endif 230 | 231 | float4 Parallax (float4 texcoords, half3 viewDir) 232 | { 233 | #if !defined(_PARALLAXMAP) || (SHADER_TARGET < 30) 234 | // Disable parallax on pre-SM3.0 shader target models 235 | return texcoords; 236 | #else 237 | half h = tex2D (_ParallaxMap, texcoords.xy).g; 238 | float2 offset = ParallaxOffset1Step (h, _Parallax, viewDir); 239 | return float4(texcoords.xy + offset, texcoords.zw + offset); 240 | #endif 241 | 242 | } 243 | 244 | #endif // UNITY_STANDARD_INPUT_INCLUDED 245 |246 | 247 | 248 | -------------------------------------------------------------------------------- /Library/BuiltinShaders/CGIncludes/UnityStandardMeta.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) 4 | 5 | #ifndef UNITY_STANDARD_META_INCLUDED 6 | #define UNITY_STANDARD_META_INCLUDED 7 | 8 | // Functionality for Standard shader "meta" pass 9 | // (extracts albedo/emission for lightmapper etc.) 10 | 11 | #include "UnityCG.cginc" 12 | #include "UnityStandardInput.cginc" 13 | #include "UnityMetaPass.cginc" 14 | #include "UnityStandardCore.cginc" 15 | 16 | struct v2f_meta 17 | { 18 | float4 pos : SV_POSITION; 19 | float4 uv : TEXCOORD0; 20 | #ifdef EDITOR_VISUALIZATION 21 | float2 vizUV : TEXCOORD1; 22 | float4 lightCoord : TEXCOORD2; 23 | #endif 24 | }; 25 | 26 | v2f_meta vert_meta (VertexInput v) 27 | { 28 | v2f_meta o; 29 | o.pos = UnityMetaVertexPosition(v.vertex, v.uv1.xy, v.uv2.xy, unity_LightmapST, unity_DynamicLightmapST); 30 | o.uv = TexCoords(v); 31 | #ifdef EDITOR_VISUALIZATION 32 | o.vizUV = 0; 33 | o.lightCoord = 0; 34 | if (unity_VisualizationMode == EDITORVIZ_TEXTURE) 35 | o.vizUV = UnityMetaVizUV(unity_EditorViz_UVIndex, v.uv0.xy, v.uv1.xy, v.uv2.xy, unity_EditorViz_Texture_ST); 36 | else if (unity_VisualizationMode == EDITORVIZ_SHOWLIGHTMASK) 37 | { 38 | o.vizUV = v.uv1.xy * unity_LightmapST.xy + unity_LightmapST.zw; 39 | o.lightCoord = mul(unity_EditorViz_WorldToLight, mul(unity_ObjectToWorld, float4(v.vertex.xyz, 1))); 40 | } 41 | #endif 42 | return o; 43 | } 44 | 45 | // Albedo for lightmapping should basically be diffuse color. 46 | // But rough metals (black diffuse) still scatter quite a lot of light around, so 47 | // we want to take some of that into account too. 48 | half3 UnityLightmappingAlbedo (half3 diffuse, half3 specular, half smoothness) 49 | { 50 | half roughness = SmoothnessToRoughness(smoothness); 51 | half3 res = diffuse; 52 | res += specular * roughness * 0.5; 53 | return res; 54 | } 55 | 56 | float4 frag_meta (v2f_meta i) : SV_Target 57 | { 58 | // we're interested in diffuse & specular colors, 59 | // and surface roughness to produce final albedo. 60 | FragmentCommonData data = UNITY_SETUP_BRDF_INPUT (i.uv); 61 | 62 | UnityMetaInput o; 63 | UNITY_INITIALIZE_OUTPUT(UnityMetaInput, o); 64 | 65 | #ifdef EDITOR_VISUALIZATION 66 | o.Albedo = data.diffColor; 67 | o.VizUV = i.vizUV; 68 | o.LightCoord = i.lightCoord; 69 | #else 70 | o.Albedo = UnityLightmappingAlbedo (data.diffColor, data.specColor, data.smoothness); 71 | #endif 72 | o.SpecularColor = data.specColor; 73 | o.Emission = Emission(i.uv.xy); 74 | 75 | return UnityMetaFragment(o); 76 | } 77 | 78 | #endif // UNITY_STANDARD_META_INCLUDED 79 | 80 |81 | 82 | 83 | -------------------------------------------------------------------------------- /Library/BuiltinShaders/DefaultResources/Font.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | Shader "GUI/Text Shader" { 4 | Properties { 5 | _MainTex ("Font Texture", 2D) = "white" {} 6 | _Color ("Text Color", Color) = (1,1,1,1) 7 | } 8 | 9 | SubShader { 10 | 11 | Tags { 12 | "Queue"="Transparent" 13 | "IgnoreProjector"="True" 14 | "RenderType"="Transparent" 15 | "PreviewType"="Plane" 16 | } 17 | Lighting Off Cull Off ZTest Always ZWrite Off 18 | Blend SrcAlpha OneMinusSrcAlpha 19 | 20 | Pass { 21 | CGPROGRAM 22 | #pragma vertex vert 23 | #pragma fragment frag 24 | #pragma multi_compile _ UNITY_SINGLE_PASS_STEREO STEREO_INSTANCING_ON STEREO_MULTIVIEW_ON 25 | #include "UnityCG.cginc" 26 | 27 | struct appdata_t { 28 | float4 vertex : POSITION; 29 | fixed4 color : COLOR; 30 | float2 texcoord : TEXCOORD0; 31 | UNITY_VERTEX_INPUT_INSTANCE_ID 32 | }; 33 | 34 | struct v2f { 35 | float4 vertex : SV_POSITION; 36 | fixed4 color : COLOR; 37 | float2 texcoord : TEXCOORD0; 38 | UNITY_VERTEX_OUTPUT_STEREO 39 | }; 40 | 41 | sampler2D _MainTex; 42 | uniform float4 _MainTex_ST; 43 | uniform fixed4 _Color; 44 | 45 | v2f vert (appdata_t v) 46 | { 47 | v2f o; 48 | UNITY_SETUP_INSTANCE_ID(v); 49 | UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); 50 | o.vertex = UnityObjectToClipPos(v.vertex); 51 | o.color = v.color * _Color; 52 | o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); 53 | return o; 54 | } 55 | 56 | fixed4 frag (v2f i) : SV_Target 57 | { 58 | fixed4 col = i.color; 59 | col.a *= tex2D(_MainTex, i.texcoord).a; 60 | return col; 61 | } 62 | ENDCG 63 | } 64 | } 65 | } 66 |67 | 68 | 69 | -------------------------------------------------------------------------------- /Library/BuiltinShaders/DefaultResources/Internal-Colored.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) 4 | 5 | // Simple "just colors" shader that's used for built-in debug visualizations, 6 | // in the editor etc. Just outputs _Color * vertex color; and blend/Z/cull/bias 7 | // controlled by material parameters. 8 | 9 | Shader "Hidden/Internal-Colored" 10 | { 11 | Properties 12 | { 13 | _Color ("Color", Color) = (1,1,1,1) 14 | _SrcBlend ("SrcBlend", Int) = 5.0 // SrcAlpha 15 | _DstBlend ("DstBlend", Int) = 10.0 // OneMinusSrcAlpha 16 | _ZWrite ("ZWrite", Int) = 1.0 // On 17 | _ZTest ("ZTest", Int) = 4.0 // LEqual 18 | _Cull ("Cull", Int) = 0.0 // Off 19 | _ZBias ("ZBias", Float) = 0.0 20 | } 21 | 22 | SubShader 23 | { 24 | Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } 25 | Pass 26 | { 27 | Blend [_SrcBlend] [_DstBlend] 28 | ZWrite [_ZWrite] 29 | ZTest [_ZTest] 30 | Cull [_Cull] 31 | Offset [_ZBias], [_ZBias] 32 | 33 | CGPROGRAM 34 | #pragma vertex vert 35 | #pragma fragment frag 36 | #pragma target 2.0 37 | #pragma multi_compile _ UNITY_SINGLE_PASS_STEREO STEREO_INSTANCING_ON STEREO_MULTIVIEW_ON 38 | #include "UnityCG.cginc" 39 | 40 | struct appdata_t { 41 | float4 vertex : POSITION; 42 | float4 color : COLOR; 43 | UNITY_VERTEX_INPUT_INSTANCE_ID 44 | }; 45 | struct v2f { 46 | fixed4 color : COLOR; 47 | float4 vertex : SV_POSITION; 48 | UNITY_VERTEX_OUTPUT_STEREO 49 | }; 50 | float4 _Color; 51 | v2f vert (appdata_t v) 52 | { 53 | v2f o; 54 | UNITY_SETUP_INSTANCE_ID(v); 55 | UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); 56 | o.vertex = UnityObjectToClipPos(v.vertex); 57 | o.color = v.color * _Color; 58 | return o; 59 | } 60 | fixed4 frag (v2f i) : SV_Target 61 | { 62 | return i.color; 63 | } 64 | ENDCG 65 | } 66 | } 67 | } 68 |69 | 70 | 71 |